- July 30, 2019
- Posted by: Taylor Johnson
- Category: Developer
Web Resources are a great way for you to add code to your Dynamics 365 forms and/or fields. Web Resources are simply “web” files that get stored within CRM. Whether you want to add JavaScript or just customize using HTML and/or CSS, Web Resources are a great way to accomplish your end goal.
Web Resources are stored within the Microsoft Dynamics 365 database. This allows your Web Resource to be used on a completely different form than the original intent. (Microsoft Got Smart)
A lot of what Web Resources are good for, is making sure that duplicate data doesn’t have the chance to be created. A good way to ensure that this data can’t be created is by copying data from fields in higher Entities. I usually keep the direction of data flowing out of Accounts and Contacts, not in.
I make it so that our team can enter information on Accounts and Contacts, but then that information gets copied to Cases whenever they are created. This makes it simper for the Service team and also forces there to only be one spot to enter data.
Lets explore down a very regular hypothetical path. Let us assume that we have a Case that was created by a client. The Case is linked to an Account through the lookup field “Customer”. I want to be able to display the value of a Field on the Account for the related Case. This is something that is not possible out of the box. We need to dig a little deeper. Lets explore a little JavaScript.
The code above goes to the “Customer” Field on the Case form. It grabs the data from the Field, and goes to that Account’s data. It grabs the data from the “State” Field, and returns to the original Case Form. From there, the Web Resource updates a State Field on the Form.
This allows the Case Form to always get information from the Account related to the Case.
To upload the Web Resource, there is not much that we have to do. Go to System Settings, Web Resources, and paste the code into a JavaScript web file.
We will now go to the Case form, double click on the “Customer” Field, and add it to the Event Handlers Section as an OnChange Event.
All there is to do now is change the value of the Customers Field.
I hope you found this article helpful. This is very powerful stuff, and actually not that bad when you break it down piece by piece.