Custom error messages in MPOS

This post is for describing how we can show custom error messages in MPOS.

MPOS standard error handlers require that the strings to be shown as error messages are entered in the following format within the resources.json file (en-US).

“string_55001” : “This is a custom error.”,

Within MPOS we could use the following snippet to display any custom error messages

let displayMessageActivity: Commerce.Activities.DisplayMessageActivity = new Commerce.Activities.DisplayMessageActivity({
title: ‘Custom Error’,
message: Commerce.ViewModelAdapter.getResourceString(“string_55001“)
displayMessageActivity.execute().done(() => {
// code to run on successful display of the error dialog
}).fail(() => {
// code to run on failure in displaying the error dialog

If however the error condition is met in the Commerce Run Time (CRT) you need to show the error message in MPOS, you can leverage the CommerceRunTimeException

throw new CommerceException(“string_55047”, “CUSTOM ERROR MESSAGE”);


One possibility is that the error messages could be coming from a third party application. On a recent integration I received a list of predefined error codes with error messages from the application.I then defined an enum in the CRT which had the values as this status codes and names as the error messages




I defined a corresponding Enum in the CRT

public enum AppError




After deserializing the response I checked the ReturnStatus code from the application and used an offset (50050) to throw the correct error message from the resources.json file

if (Enum.IsDefined(typeof(AppError), res.ReturnStatus))
AppError err = (AppError)res.ReturnStatus;
throw new CommerceException(“string_” + (50050 + res.ReturnStatus) , err.ToString().Replace(“_”, ” “));

<Update>One thing you need to be aware is that the Error Status Code and Error Messages returned by the application should be constant. Any changes would mean that the MPOS package will need to be regenerated and redeployed.

I got following suggestion from my Mentor Mani (from Microsoft) for displaying the custom error messages- you can set custom properties in the response (CRT) and then parse the response in MPOS and show your message, you can also use extension properties and then parse it in MPOS. With this approach no need to define the error messages in resources.json.


Hope this helps

-Hitesh Manglani









MPOS, Retail Server – JSON API Integration

Recently I had to work on developing an integration between MPOS and a CRM application via Retail Server/CRT. The REST APIs provided where JSON based and I needed C# classes to deserialize the response.

My gut feel said that there should be a tool to do this and I need not create the required classes and properties manually.

Sure enough after some web search, I found

This is an awesome site where you can provide a sample JSON API response and get the C# classes that can be used to deserialize the JSON.

Hope this helps  you save some time, just as it helped me.

-Hitesh Manglani

Dynamics 365 for Operations and TLS 1.2

In my first Dynamics 365 for Operations project we had to implement an integration between the Azure hosted Dynamics 365 for Operations Retail Server and an on premise web api server (for more information on the overall Retail Topology do refer this link MPOS Technical Architecture).

The integration worked fine in our Development environment but when promoted to UAT sandbox the integration broke with the following error

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

and initially we could not understand why, after some investigation we could find out the cause being that Dynamics 365 for Operations configuration enforced a TLS 1.2 protocol while the destination server supported only TLS 1.0 and 1.1.

The following resources were very helpful to arrive at the conclusion

Last but not the least, an excellent resource was the following link by John Louros.

In this blog, John has provided a nifty console application which was extremely helpful in understanding what was going wrong in the integration, by trying all combinations of TLS protocols between the source and destination it lets you know which protocol is supported and which one is not.


-Hitesh Manglani