Creation Of Web Resource JavaScript Type In Dynamics CRM

Introduction

In Dynamics 365 CRM, any functionality cannot be achieved through OOB [Out of Box] functionality, the first thing that comes into mind was customizations. So, basic customizations can be achieved starting with Web resources (js type) under code, especially through JavaScript. As a business case, a new web resource will be created in Contact Customizations Solution.

Step 1

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

Creation of Web resource JavaScript Type in Dynamics CRM

Step 2

After Step 1, Click on + New button -> More -> Web resource as shown in the below figure.

Creation of Web resource JavaScript Type in Dynamics CRM

Step 3

After Step 2, create a JavaScript file with name ContactFormScripts.js in visual studio code with 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
}

 as shown in the below figure.

Creation of Web resource JavaScript Type in Dynamics CRM

Step 4

After Step 3, provide the following inputs

Upload file : upload a javascript file ContactFormScripts.js
Display name : contact
Name : contact [cr5bc_contact]
Type : JavaScript (JS) from Contact Form scripts
Description: contact js logic

And click on save as shown in the below figure.

Creation of Web resource JavaScript Type in Dynamics CRM

Step 5

After Step 4, you will see contact web resource gets created in Contact Customizations solution, select newly created web resource and click on Publish as shown in the below figure.

Creation of Web resource JavaScript Type in Dynamics CRM

Note

  1. Make sure to publish all customizations as well.
  2. Don’t forget to keep some code in JavaScript web resource, otherwise your Dynamics will not allow you to upload empty js file.
  3. I have more concentrated on creation of web resource that’s why not explained about the code that is present inside JavaScript file.

Conclusion

In this way, one can easily create a web resource of type JavaScript to perform customizations for a given business requirement.