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.
Implementing a new ERP system in an organisation is always a challenge. Users question whether they will be able to cope with analysing the data flow in an integrated system without external support. The accountant wonders whether all the set-up accounts are correct. The chief technologist cannot get rid of troublesome thoughts about whether the routings and boms are set up optimally. This is why it is so important to have a reliable service team to help the company control the system in the post-implementation stage. In this article, we take a look at the issues surrounding the implementation of an ERP system and the benefits of maintaining proactive service support.
328.77 million terabytes of data are generated every day - this is the estimate for the first quarter of 2023 (1). These are massive amounts of data on a global scale. On a smaller scale, such as an enterprise, it's difficult to estimate because it depends on the organisation in question, but one thing is certain - collecting, processing and analysing this data is the key to business success today. Why is the Data Lake service so important for data analysis and reporting in Microsoft Dynamics 365 Finance and Operations? How can you tame the data by integrating Microsoft Power BI analytics with Data Lake? We have drawn up some tips.
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.