RESX web resources have been introduced for quite sometime but unfortunately even when I see project implementations today, I see constants file being used instead of Resource files. What more, you can even show specific values based on logged in user language. This blog post is not about how you can create a resource file and stuffs but more importantly using the Xrm.Utility.getResourceString method of WebApi both on your entity forms as well as webresources.
For the sake of completeness of this blog, let’s first create a resource file. Open any xml editor of your choice and let’s use the following resource content.
Let’s save the file with .resx extension.
Now let’s go ahead and create a webresource with the following content.
Webresource name – new_/strings/test.1033.resx
Type – Resource File (resx)
Observe the webresource name. I have included English language code (1033) in the file name.
Now let’s focus on the Xrm.Utility.getResourceString method.
1. Get Resource value on Entity Form
While this step is not mandatory, it is advised to do so. Adding the resource file in the dependency list will make sure you don’t get any reference errors while accessing resource file.
Now when you try to access the resource value based on the key, the appropriate value is received depending on the user’s language.
As you can see from the above screenshot, check for how I have used the resource file name. If the user language is English, it shall search for the file ending with extension .1033.resx. If not matching file is found, it shall default to the generic file. That’s why it is always suggested to create generic resource file without any language code being mentioned in the file as fallback.
2. Get Resource Value on HTML webresource embedded in Entity Form
Now the next step is to access Resource file from HTML webresource embedded in entity form. It’s quite easy. Include ClientGlobalcontext.js.aspx with appropriate path in the HTML file and then use the resource file in dependency area of HTML web resource.
And the same code above shall work.
3. Get Resource Value on HTML webresource in separate window
Now let’s say you want to open a webresource in a separate window using Xrm.Navigation.openForm. And you follow the same steps as mentioned earlier. However this time, you will get an error while trying to access Xrm.Utility.getResourceString. Fortunately I came across Andew’s blog which helped me to resolve the issue. You can follow it here.
Hope this helps!
Our product offerings:
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)