| 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:
Lets create a map.. 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 References: 1. http://msdn.microsoft.com/en-us/library/bb278211(AX.10).aspx 2. MorphX IT
Technorati Tags: Dynamics AX,Dynamics AX Table Maps 引用通告此日志的引用通告 URL 是: http://dynamic-ax.spaces.live.com/blog/cns!13619E6948204DE3!363.trak 引用此项的网络日志
|
|
|