-->

AX 2012 - Understanding AOT Maps with an example

maqk® by Unknown | 7:17 PM

Understanding AOT Maps with an example

Subject: AOT Maps

Audience: Dynamics AX Developers

Background

Maps are not new concept in software development actually. They are table wrappers to achieve general behavior. However for lame dude(s) like me, these definition words have not been enough.

Problem

The term allotted to Maps, "Map" itself is a bit confusing. But an example can really help understanding. And Maps are used everywhere, but in comparison to tables and classes ( see these building blocks are essential for any kind of most basic development), use of maps are quite rare.

Example

I have been browsing PurchTableHistory table. A method came into my consideration where I see the use of Map.  

The method, PurchTableHistory[T] >> initFromPurchTable() declares several maps based on localized buffers. Look at the following code

// Code example

PurchTableMap purchTableMap;
purchTableMap.data(_purchTable.data());
this.data(purchTableMap.data());
First, the row from PurchTable is copied to the map variable, 'purchTableMap', and then, the history buffer gets the same row but form map, and not from the original source, purchTable buffer

WHY ? Their must be a genuine need ? Why don't we copy from the original PurchTable buffer  ? Becuase we cannot :) becuase of schema change. See if most of the fields are same but not with exact field names, types and filed list count, we cannot copy a row from one table to another using xRecord[C].data() simply because of schema mismatch.

Here is where map can work, since the different name same type and purpose fields are MAPPED in the MAP :). Fields with different names from different tables are mapped to consistent names in map, so that you can use them to map one row ( from one table buffer) to another table.

Updated: Rephrasing the above in other words, map can be used to manipulate common schema among different (and having entirely different schema ) tables. It is like not knowing a buffer at runtime, expecting from it to be implementing a consistent schema with labelling issu

One more thing, when using maps,
field count doesn't matter since the map will only care and execute on the schema defined in the map. It simply would not care for schema defined in the mapped tables, it would only care for the schema defined in the MAP

Happy MAPPING

Links

0 comments:

Post a Comment

top