Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Wednesday, June 26, 2013

Map in AX

Hi,

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

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...