Tuesday, 15 October 2013

Maps


https://amazingax.wordpress.com/2013/01/13/microsoft-dynamics-ax-2012-maps-in-aot/
http://ajstudi0.blogspot.in/2012/10/microsoft-dynamics-ax-maps.html



Create a class and 4 methods as follows depicts example of map in AX
public class CreateCountryCountMap
{
Map countryMap;
}
private void searchCustomers()
{
CustTable custTable;
Counter cnt;
LogisticsAddressCountryRegionId countryId;
LogisticsAddressCountryRegionName countryName;
countryMap = new Map(Types::String, Types::Integer);
while select custTable
{
countryId =
custTable.postalAddress().CountryRegionId;
countryName =
LogisticsAddressCountryRegion::find(countryId).displayName(
);
cnt = 0;
if (countryMap.exists(countryName))
{
cnt = countryMap.lookup(countryName);
countryMap.remove(countryId);
}
cnt++;
countryMap.insert(countryName, cnt);
}
}
private void loopCountries()
{
MapEnumerator mapEnumerator = new
MapEnumerator(countryMap);
while (mapEnumerator.moveNext())
{
info(strFmt("There are %1 customers in %2",
mapEnumerator.currentValue(), mapEnumerator.currentKey()));
}
}
private void run()
{
this.searchCustomers();
this.loopCountries();
}
static void main(Args _args)
{
CreateCountryCountMap countryCount = new
CreateCountryCountMap();
countryCount.run();
}

No comments:

Post a Comment