Microsoft has provided plenty of tools for use when out-of-the-box customizations fall short. Using custom web resources on forms can be a powerful tool, but it should integrate seamlessly with the form. To accomplish this, the web resource can hook onto the save of the form. This provides an easy way for users to interact across the different parts of the form without having to worry about multiple toolbars. In today's blog, we'll show you how it's done!
Let's say we have a web resource that surfaces information from a different entity, or a different source all together, and allows user input. In just a few simple steps, we can save any data we need from the web resource at the same time as the form.
1. Retrieve initial modifiedon information:
var modifiedon = parent.Xrm.Page.getAttribute("modifiedon").getValue();
While the user interacts with the web resource, it is setting the modifiedon field to either the saved date or a new date. This will make the form appear dirty whenever the web resource requires a save, or other function call, to happen. Users will no longer know they are interacting with a separate web resource.
We hope this comes in handy for you. For more tips and tricks – be sure to check out our blog!
Language Localized Web Resources
When creating the resource files for each language there are few points that need to be remembered. In the web resource, you'll need to include the numeric language code in the Name as well as specify the Language type in the Content settings. In this example, 1033 is English and 1036 is French. Also, make sure the key is the same in each file – example "Greeting."
In this example, Visual Studio is being used to create the RESX files but under the hood, they are just XML files. The schema is a bit complex so if possible use a tool to create them rather than doing it manually.
In order to get a localized value from one of these files you can use the new "Xrm.Utility.getResourceString" method. The first parameter is the first part of the web resource Name including the prefix. The second is the key from the RESX file. The specific language is not defined anywhere. The result will come from the RESX file that matches the logged in user's default language. If it doesn't exist, it will fall back to the organization's base language.
Once the setup is complete, you can bind scripts to form events as you normally would.
The resulting alert displays the value based on the logged in user's language selection with is found under the user options.
When the language is set to English, the result comes from the English RESX file.
When the language is set to French, the result comes from the French RESX file.
There are times when we would like to search the content of our web resources to look for specific unsupported code or to just search for specific content.
Typically, this would be done by searching a source code repository and looking for matching files. While this works, sometimes it would be easier and would save time if we could pass in multiple keywords and generate a file that lists all the web resources with those keywords. This is particularly helpful when you have clients upgrading to newer version of Dynamics 365.
How to Search Web Resources
The approach below describes how we can search by using the Dynamics 365 Service. Alternatively, if you have an On-Premises environment you could request your Administrator to run the SQL query and return the results.
1. Let's define the keywords we want to search and any web resources we want to exclude from the search. This would usually be third party solutions that we have added, etc.
2. We can now use a Query to retrieve the content of web resources from Dynamics 365 by specifying our criteria to only return the web resources we are interested in. Since we cannot directly query the content of the web resource, we would have to query it after we convert it from the base 64 string.
3. Once we have the web resource content mapped to the name of the web resource, we can use the keywords we have defined to start searching. Since a web resource could match on multiple keywords, we get the distinct one in the last step.
4. Now that we have the list of all the web resources, we can output this information to a file easily.
There you go – a quicker way to search for your custom web resource content. Subscribe to our blog today to start receiving more Dynamics 365 tips and tricks in your inbox!