JSON utility class for AX 2012Continue reading
When implementing Retail for Dynamics AX you could have a lot of different retail channels and with it a lot of different messages that need to communicate with Dynamics AX.
One possibility is to send JSON messages to Microsoft Dynamics AX which is a lightweight data-interchange format. First rule is the table field that will store the received JSON message should be of type ‘String’ and fixed character length of 1999 which we can add it as a new field in ‘RetailTransactionTable’. In this scenario we will receive a JSON message with payment information for particular Sales order. So let’s go step by step:
The first step is to create a class called ‘JsonHelper’ and add the main parsing method as follows:
static Array parseJson(str _json)
int jsonSubstrNo, i;
Array returnArray = new Array(Types::Class);
// extract the json substrings and add them to a Array
textBuffer = new TextBuffer();
while (textBuffer.nextToken(0, #LBracket+#RBracket))
if ((jsonSubstrNo mod 2) > 0)
con += #LBracket + textBuffer.token() + #RBracket;
for (i = 1; i <= conLen(con); i++)
returnArray.value(i, RetailCommonWebAPI::getMapFromJsonString(conPeek(con, 1)));
The above method extracts the JSON values and adds them into a container which then is being converted to a map with which we are filling a result array.
Then add the methods that will process the array information from the previous step. One sample method is:
static SalesTable jsonArrayToPaymentInfo(SalesTable _salesTable)
jsonArray = JsonHelper::parseJson(_salesTable.ANG_PaymentInformation);
for (i = 1; i <= 1/*jsonArray.lastIndex()*/; i++)
data = jsonArray.value(i);
mi = new MapIterator(data);
value = data.lookup(mi.key());
// initialize the payment fields in sales table before the order is created
_salesTable.ANG_Payment_CreatedDate = JsonHelper::convertJsonDateToUtc(value);
_salesTable.ANG_Payment_Details = value;
_salesTable.ANG_Payment_isPaid = !value? NoYes::No : NoYes::Yes;
_salesTable.ANG_Payment_MBEntity = value;
_salesTable.ANG_Payment_Mode = value;
_salesTable.ANG_Payment_PayDate = JsonHelper::convertJsonDateToUtc(value);
_salesTable.ANG_Payment_Reference = value;
So in the above code we have used a macro ‘ANG_JsonAttributeDef’ which holds the definitions of the attributes that we should decode. It should look like following:
//Define the json attributes for payment information
In the previous step we have used also additional method called ‘convertJsonDateToUtc’ which is used for converting the time from JSON message into an AX date time value. So this is the method:
static utcDateTime convertJsonDateToUtc(str _jsonDateTime)
utcDateTime resultDateTime, unixStartTime;
str jsonDateTimeTmp, jsonTimeZoneTmp;
jsonDateTimeTmp = subStr(_jsonDateTime, strFind(_jsonDateTime,'-',1,strLen(_jsonDateTime))-1, -(strFind(_jsonDateTime,'-',1,strLen(_jsonDateTime))-7));
jsonTimeZoneTmp = subStr(_jsonDateTime, strFind(_jsonDateTime,'-',1,strLen(_jsonDateTime))+1,4);
unixStartTime = DateTimeUtil::newDateTime(mkDate(1,1,1970),0,Timezone::GMT_DUBLIN_EDINBURGH_LISBON_LONDON);
resultDateTime = DateTimeUtil::addSeconds(unixStartTime, str2int64(jsonDateTimeTmp)/1000);
resultDateTime = DateTimeUtil::addHours(resultDateTime, str2int(subStr(jsonTimeZoneTmp, 1, 2)));
And the usage of this class is shown in the following code which is inserted into ‘CreateOrder’ method in the ‘RetailOrderManager’ class:
//parse the json for payment information and initialize the corresponding fields
salesTable = ISL_JsonHelper::jsonArrayToPaymentInfo(salesTable);
And ‘RetailOrderManager’ class is used to create a sales order and related information from a given Retail transaction table entry. And Retail transaction table gets filled by the P-job which is asynchronous way of pulling POS data to HQ.
And so that’s all for this solution that shows that Microsoft Dynamics AX could be integrated with almost any external system.
The retail industry is still dealing with the effects of the pandemic that lasted almost three years. In addition to this, further global events are causing disruption to the supply chain or financial stability of many retailers globally. As the industry confronts new challenges shaped by economic and geopolitical factors, it also faces trends influenced by changing customer expectations and needs. Here are 5 developments and trends to watch.
An interactive, AI-powered support for sales, customer service, marketing, and supply chain - Microsoft Dynamics 365 Copilot leverages generative AI and natural language processing technology to perform simple, yet time-consuming daily tasks that workload employees but can be automated.
Every company management facing a system change wonders what steps should be taken to ensure that this change does not cause turbulence to its business. Identical dilemmas are faced by any IT company that provides services to implement a new system. I will focus on these dilemmas today.
Artificial intelligence (AI) and machine learning (ML) technologies are changing business every day - just as new tools and services are frequently emerging to expand their use cases. PwC estimates that the impact of these technologies on the global economy will add approximately $15.7 trillion to its value by 2030 (1).