Trending: Jawaan


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


View the original article here

1 Responses to “Table Maps in Dynamics AX”

Anonymous said...
March 15, 2013 at 5:14 AM

Does your blog have a contact page? I'm having a tough
time locating it but, I'd like to send you an e-mail. I've
got some ideas for your blog you might
be interested in hearing. Either way, great blog and I look forward to
seeing it develop over time.

Feel free to visit my webpage :: My Site
My page: Please visit my site


About Me