A blog on Dynamics 365 for Operations – Retail

Category: Integration

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

e.g.

INVALID_OPTION = 152

ERROR_NEW_PASSWORD_CANNOT_BE_THE_SAME_AS_OLD_PASSWORD = 180

I defined a corresponding Enum in the CRT

public enum AppError
{

INVALID_OPTION = 152

ERROR_NEW_PASSWORD_CANNOT_BE_THE_SAME_AS_OLD_PASSWORD = 180

}

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>

I later discovered a simpler way by following the Retail SDK example

throw new CommerceException(“Microsoft_Dynamics_Commerce_30104”, “Custom error”)
{
LocalizedMessage = “Custom error message returned by the third party app”;

};

</Update>

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 https://jsonutils.com/

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

https://docs.microsoft.com/en-us/dynamics365/unified-operations/retail/retail-peripherals-overview

https://blogs.perficient.com/microsoft/2016/04/tsl-1-2-and-net-support/

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

https://www.johnlouros.com/blog/disabling-cryptographic-protocols-for-pci-compliance

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

 

 

© 2023 Dynamics Journal

Theme by Anders NorenUp ↑