Link Web Resource To A Form In Dynamics CRM

Introduction

In Dynamics 365 CRM, post creation of a web resource, to use it in CRM Form for a selected entity then we must add web resource into Form Libraries present at form level and then tie it to Event Handlers for a selected Event on Main Form. As an example, in Contact Customizations Solution for Contact Entity Main Form a web resource will be added to perform customizations on Contact Record.

Step 1

Login to the required environment and select required solution [Contact Customizations Solution in this case] as shown in the below figure.

Link Web resource to a Form in Dynamics CRM

Step 2

After Step 1, select Contact table and navigate to Forms section and select Contact Main Form and click on Edit Form -> Edit Form in new tab as shown in the below figure.

Link Web resource to a Form in Dynamics CRM

Step 3

After Step 2, in a new tab Contact Entity Main form gets opened and go to Form Libraries area to the left side of the screen and click on Add Library and search for web resource with name contact and click on Add as shown in the below figure.

Link Web resource to a Form in Dynamics CRM

Step 4

After Step 3, under Form Libraries newly added Library cr5bc_contact will appear as shown in the below figure.

Link Web resource to a Form in Dynamics CRM

Step 5

After Step 4, select Contact Events under Contact Main Form and under On Load click on + Event Handler and select cr5bc_contact web resource under Library drop-down as shown in the below figure.

Link Web resource to a Form in Dynamics CRM

Step 6

After Step 5, we must provide Function Name which can be fetched by opening contact webresource and take handleOnLoad function and fully qualified function name as follows

Function

ContosoVaccination.Scripts.ContactForm.handleOnLoad

in the below code

if (typeof(ContosoVaccination) == "undefined") {
    var ContosoVaccination = {
        __namespace: true
    };
}
if (typeof(ContosoVaccination.Scripts) == "undefined") {
    ContosoVaccination.Scripts = {
        __namespace: true
    };
}
ContosoVaccination.Scripts.ContactForm = {
    handleOnLoad: function(executionContext) {
        console.log('on load - contact form');
    },
    __namespace: true
}

And save it in notepad as shown in the below figure.

Link Web resource to a Form in Dynamics CRM

Step 7

After Step 6, provide the function name as ContosoVaccination.Scripts.ContactForm.handleOnLoad and select pass execution context as first parameter check box and then click on Done button and save and Publish as shown in the below figure

Link Web resource to a Form in Dynamics CRM

Step 8

After Step 7, in Contact Main Form under On Load, newly added event handler will appear as shown in the below figure

Link Web resource to a Form in Dynamics CRM

Step 9

After Step 8, to test this open any existing or new contact record and can observe in console window on load - contact form text will be shown as shown in the below figure

Link Web resource to a Form in Dynamics CRM

Note

  1. Make sure to publish all customizations and upload JavaScript (js) file.
  2. For other Forms for an entity we can add a web resource in the same way.
  3. Same process is applicable for Save Event as well.

Conclusion

In this way, one can easily link/refer to a web resource in CRM Forms in entities easily.


Similar Articles