JScript Web Resources - Microsoft Dynamics CRM

What is JScript Web Resources?

JScript web assets are probably the most essential type of web assets that you will be using with Microsoft Dynamics CRM.

Applications of JavaScript in CRM

Form event Programming

Form event Programming is used to handle client-side behaviors such as what happens when a user opens a form, changes a few information, moves through tabs, etc. To achieve such client-aspect interactions you may be writing JavaScript code and including it as a JScript internet resource in CRM. however, the JavaScript code which you may write has to use Dynamic CRM’s Xrm.page version and not the standard JavaScript DOM. using Xrm.page version is Microsoft’s way of coding which ensures that any code you write using this version may be compatible with any future versions of CRM.

Web Resources

In addition to being used in form event Programming, JavaScript is used in other applications of CRM such as −

  • Open forms, views and Dialogs with a unique URL.
  • Using OData and soap endpoints to interact with web services.
  • Referencing JavaScript code inside different web assets (including HTML web resources).

In such instances, you will write your JavaScript code (using Xrm.page version) and add it as a JScript web resource in CRM, that can then be referenced anywhere with a unique URI.

Ribbon Customizations

Finally, one of the different common use of JavaScript is to address ribbon customizations such as −

  • Show/hide ribbon buttons based on some logic
  • Enable/Disable ribbon buttons based on some logic
  • Handle what happens when you click a certain ribbon button

To handle such scenarios, you may write your JavaScript logic (using Xrm.page model) and then add it as a JScript web resource. This web resource can then be referenced inside the ribbon button’s XML and we can specify which technique in which JScript report to name to test if a ribbon button have to be displayed/hidden or enabled/disabled or manage click events.

Xrm.page Object Model

Following is the Xrm.page object’s hierarchy showing the to be had namespaces, objects, and their collections. you may be the usage of these properties while writing JScript code.

JScript Web Resources

Namespaces

S.No

Object & Description

1

Context

Provides methods to retrieve context-specific information such as organization details, logged-in user details, or parameters that were passed to the form in a query string.

2

Data

Provides access to the entity data and methods to manage the data in the form as well as in the business process flow control.

3

UI

Contains methods to retrieve information about the user interface, in addition to collections for several sub-components of the form.

Objects

S.No

Object & Description

1

Entity

Provides method to −

  • Retrieve record information
  • Save method
  • Collection attributes

2

Process

Methods to retrieve properties of business process flow.

3

Navigation

Provides access to navigation items using items collection.

4

FormSelector

Uses Items collection to access available forms to the user. Also uses the navigation method to close and open forms.

5

Stages

Each process has a collection of stages that can be accessed using getStages method of process.

6

Steps

Each stage comprises of various steps that can be accessed using getSteps method of stage.

Collections

S.No

Collections & Description

1

Attributes

Provides access to entity attributes available on the form.

2

Controls

ui.controls− Provides access to each control present on the form.

attribute.controls− Provides access to all the controls within an attribute.

section.controls− Provides access to all the controls within a section.

3

Items

Provides access to all the navigation items on a form.

4

Tabs

Provides access to all the tabs on a form.

5

Sections

Provides access to all the sections on a form.

Supported Events in Form Programming

The shape Programming using Xrm.page version allows you to handle the following shape events –

  • onLoad
  • onSave
  • onChange
  • TabStateChange
  • OnReadyStateComplete
  • PreSearch
  • Business Process Flow control events

Form Programming Example

In this example, we can placed some validations at the contact shape based at the PreferredMethodofCommunication that the user selects. hence, if the user selects his/her preferred technique as email, then the email field have to become mandatory and similarly for different fields of phone and Fax.

Step 1 − Create a JavaScript file named contacts.js and copy the following code.

Step 2 − Open the contact entity form by navigating to Settings → Customizations → personalize the system → touch entity → forms → main form.

Step 3 − click form properties.

JScript Web Resources

Step 4 − From the Form Properties window, click Add.

JScript Web Resources

Step 5 − In the next Look Up Web Resource Record window, click New since we are creating a new web resource.

JScript Web Resources

Step 6 − In the New Web Resource window, enter the following details −

Name − new_contacts.js

Display Name − contacts.js

Type − JScript

Upload File − Upload the JavaScript file that you created from your local machine.

JScript Web Resources

Step 7 − click save followed through submit. After this close the window and you will be again to look Up web resource file window.

Step 8 − here, you can now see the new_contacts.js web resource. choose it and click add. you have now successfully added a new web resource and registered it at the form.

JScript Web Resources

Step 9 − Now we will upload an event handler on the change of preferred technique of communication area. This event handler will name the JavaScript function that we just wrote. choose the following options from the event Handler section.

Control − preferred technique of communication

Event − OnChange

Then, click the Add button, as proven in the following screenshot.

JScript Web Resources

Step 10 − in the next window of Handler properties, we will specify the technique to be called while the change event occurs.

Choose Library as new_contacts.js and feature as validatePreferredMethodOfCommunication. click ok.

JScript Web Resources

Step 11 − You will now be able to see the Form Library (Web Resource) and events registered on it. Click OK.

JScript Web Resources

Step 12 − Click Save followed by Publish.

JScript Web Resources

Step 13 − Now open any contact form and set the preferred technique of communication as phone. this can make the mobile phone area as mandatory. if you now try to keep this contact with out entering any mobile number, it will give you an error saying ‘You need to offer a value for mobile phone’.

JScript Web Resources

Conclusion

In this chapter, we started by way of understanding the three important applications of JavaScript in CRM. Later, we explored the Xrm.page version and used it to analyze form programming along with an example.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Microsoft Dynamics CRM Topics