CRM Crate

In this course we will learn to use JavaScript in Microsoft Dynamics CRM. The JavaScript used in Dynamics CRM is added by creating JavaScript web resources. Before starting, make sure to go through the below courses to understand the basic concept of JavaScript.

Areas where you can use JavaScript?

You can use JavaScript to perform actions in form scripts, command bar (ribbon) commands, and web resources.

  • Form scripts

The most common use of JavaScript in Microsoft Dynamics 365 is to add functions as event handlers for entity form events. Client-side scripting using JavaScript is one of the ways to apply custom business process logic for displaying data on a form in Dynamics 365 CRM.

  • Command bar (ribbon) commands

When you customize the Microsoft Dynamics CRM command bar or ribbon bar, you can configure commands for controls that you add. These commands contain rules that control whether the control is enabled and what action is performed when the control is used.

  • Web Resources

Dynamics 365 CRM provides an organization-owned entity that stores a binary representation of a file that can be accessed by using a URL. This file is called a “web resource”. There are several types of web resources. A web resource that represents a JavaScript library is called a “JavaScript web resource”. You can use a webpage (HTML) web resource to provide a user interface with JavaScript libraries included just as you would for files on a web server. Because these files are part of Dynamics 365 Customer Engagement , users who access them are already authenticated. Therefore, you can use Dynamics 365 Customer Engagement (on-premises) web services without having to write code to authenticate the user.

How to register a JavaScript code in Dynamics CRM Form?

We will consider an example where we will trigger the JavaScript code on saving the Account record. Below is the sample code which we will use to trigger the alert after saving the Account record.

function Test(executionContext) {
var formContext = executionContext.getFormContext();

//Sending Alert. 
alert("Account Form Is Saved!!");

}

Once you have the JavaScript code ready. Navigate to CRM >> Settings >> Customization >> Customize the System.

Now we have to create a new Web Resource File. Expand Components >> Web Resources >> Click on New.

Fill the basic details, in field “Type” select “Script(JScript)”. Click on field “Text Editor”, copy paste your JavaScript code and click on Ok. Finally, click on Save and Publish the web resource.

Now, we have to register the above created web resource in the On Save event of Account form. Expand Components >> Entities >> Account (Your entity of choice) >> Forms. Select the form on which you have to trigger the JavaScript code.

Once the form editor gets open, click on “Form Properties”. The Form Properties has two major tabs which are Form Library and Event Handlers. The web resource file is registered in the Form Library and the function is been called using the Event Handlers.

To register the web resource, click on Add in the Form Library tab. Search for the previously created new web resource file and click on Add.

The new web resource is successfully added in the Account entity’s form library. Now you will have to add the function (JavaScript method name) so that your JavaScript code gets called in the On Save event. In the Event Handler, click on Event and select “OnSave”. Later, click on Add, select the above created web resource name in the Library field. Enter your specific function name in the field Function and click on Ok.

Note : – Since we are using the execution context, click the checkbox called “Pass execution context as first parameter”.

The web resource and the function is registered on the OnSave event of Account record. In order to deploy the changes, click on the Save and Publish.

Validate the deployed changes in Account entity.

Open the CRM >> Navigate to Account >> Click on New >> Fill the mandatory information and save the Account record. Now, after click on save, system will be throwing an alert with the message given in the JavaScript code.

CRM Crate

All In One Platform For Learning Microsoft CRM.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
error: CRM Crate Security Engine - Disabled Right Click & Selection!
0
Would love your thoughts, please comment.x
()
x

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.

Join CRM Crate Now!

Join CRM Crate and get all the latest updates in Microsoft CRM.

Learn & Grow Together