Most of the times, we have validation or error messages to be shown to user during client side validations in D365. We directly hardcode these message in the JS functions. Instead we can use Resources file(.resx) to store all the messages in common file and use it wherever it is required. This helps in maintaining the code and also promotes reusability.
This file format is also supported in web resources.
Creation of Resource file:
In visual studio, resource file can be directly created as shown below.
Add the validations message as shown below and save the file(eg:UserValidationMessages). You can add as many messages you want.
Open D365 web resource and upload this file by selecting Type as 'String(RESX)' as shown below.
Below is the sample code to retrieve the messages from resource file.
var emailValidationMessage = Xrm.Utility.getResourceString("new_UserValidationMessages.resx", "AccountEmailAddressValidationMessage");
The resource file can be updated anytime by downloading the file from webresource url as shown below.
Save the file.
Open in Visual studio and update the message.
This file can be updated back to web resource as shown below.
This approach can also be used in multi-language supported applications where message should be shown based on the user selected language.
Comments
Post a Comment