Mohammed 的个人资料Dynamics AX日志留言簿网络 工具 帮助

日志


9月16日

Table Maps in Dynamics AX

-Mohammed Rasheed

Dynamics AX Table Maps are one of the most useful elements of the Dynamics AX application Object Tree. I am using the word ‘Table Maps’ to differentiate from the foundation class Map.

The Class Map, enables you to link (or map) Key-Value pairs. However Table Maps (AOT > Data Dictionary > Maps) enable developers to map fields that are common across multiple table and apply logic that could be reused across tables..

Let me give you an example..

I once wrote a Data Conversion application... it started off as a job that basically read csv files and populated staging tables... a user would then validate/correct the data on a form and then on a push of a button, the main ax tables would be populated.. The technique worked really well for us... and we later on adopted the same technique to import Trade Agreements and Item Coverage. However, when are data set became really large, things became a bit hard to manage... we were having duplicate item issues, problems with users not being able to validate all items, hence some of the items were ending up with 0 selling prices..... So very soon I had to add code to check if the item was duped and if so highlight it.... also had to check for item prices on both inventTableModule and PriceDiscTable... Not at all a hard thing to do..

But I was bothered by the fact that I was duplicating code across numerous methods (and jobs for ad hoc updates)..... I wrote a class that would validate data... but I could not write one method that would work for all table buffers.. for example.. I wasn’t only validating itemId.. I was also validating Dimensions, prices, customers, etc etc.... not I could have written methods that took a single field as a parameter.. like a method that validated only itemid, another method that validates dimensions and so on...but that would have meant throwing away my OO design principals, which are really dear to me..

So I had 2 options here..

1. use Reflections.. some fancy things with my code [ dint have the time for it though]

2. Or keep it simple and use Maps..

I obviously decided to use maps. And I have been a fan even since I used them... I think the main benefits of using Dynamics AX Table Maps are:

  • Code-reuse – one can write methods on maps and then use that code across the various table associated with the map..
  • Easy to use J – surprisingly easy to use... maps lets one associate map fields with table fields.. the good thing is that irrespective of what the fields names are on the table, a programmer will have one consistent set of fields to code for.

Lets create a map..

clip_image001

Ok so in this example I created 2 staging table for Items and Trade Agreements.. and I need to validate if the itemId on the staging table actually exists in InventTable.

I created a Dynamics AX Table Map (InventValidationMap_MR) and added the itemID field to it..

The next step was to map it to the 2 staging tables... Notice the itemId field is referred to as PriceDiscItemRelation on the Trade Agreement staging table.

Next I wrote a method on the Map that checks if the item exists in InventTable

boolean checkIfItemExistsInInventTable(InventValidationMap_MR _inventValidationMap)

{

// this method checks if the item exists in InventTable

;

return InventTable::exist(_inventValidationMap.ItemId);

}

Now lets write a job that calls upon the map. Notice that Maps are declared and used just like tables.

static void checkIfItemIsValid(Args _args)

{

TradeAgreementsStagingTable_MR tradeStagingTable;

InventPriceStagingTable_MR inventStagingTable;

InventValidationMap_MR InventValidationMap;

;

tradeStagingTable.PriceDiscItemRelation = '1000'; // Valid item id

inventStagingTable.ItemId = '3313ds23'; // invalid item id

if(!InventValidationMap.checkIfItemExistsInInventTable(inventStagingTable))

{

// i.e. the item dose not exists in invent table...

info("Not in invent");

}

if(InventValidationMap.checkIfItemExistsInInventTable(tradeStagingTable))

{

//i.e. the ite exists in invent table

info("In Invent");

}

}

If you notice I am using the same method (obviously with the same parameter signature), but passing different table buffer types....Dynamics AX automatically maps the table fields to the map fields.

Have a go at Maps today.. They are really helpful.

-

Mohammed Rasheed

www.dynamic-ax.co.uk

References:

1. http://msdn.microsoft.com/en-us/library/bb278211(AX.10).aspx

2. MorphX IT

 

评论

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

引用通告

此日志的引用通告 URL 是:
http://dynamic-ax.spaces.live.com/blog/cns!13619E6948204DE3!363.trak
引用此项的网络日志