preloader-matrix

Alfasith

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();
}

 

Share on email
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest

Leave a Reply

Your email address will not be published.