USD – Call Events from JavaScript

Within Unified Service Desk (USD) for Microsoft Dynamics CRM 2016 its possible to call custom USD events directly from your CRM forms using JavaScript. In this post I will show how to create and call a custom event.

I will demonstrate this capability with a simple example. In my example, whenever the website field is changed on my account form I will open a USD tab containing the new website. The steps involved are;

  1. Create a hosted control.
  2. Create an action.
  3. Create an Event. (And add the action.)
  4. On CRM form, add some JavaScript to call the event.

Step One – Create a hosted control.

I am going to assume you are already showing the account entity in a tab but we are going to need an additional hosted control to display the webpage for the account.

Field Description
Name Account Website
Display name [[Account Website.ul]]

This will give the tab a heading of whatever url is displayed in the Account Website name.

USD Component Type Standard Web Application
Hosting Type IE Process (I almost always use IE Process!)
Application is Global Not Selected
Display Group MainPanel

You could also use RightPanel or even FloatingPanel if you prefer.

Step Two – Create an action.

Next we will need an action that will navigate to whatever website is entered on the CRM form.

Field Description
Name I called mine Account Website – Navigate ([[WEBSITE]]) but you could use a different name if you’d prefer!
Order This is optional as I am only working with 1 action, so the order has no real effect!
Hosted Control Account Website
Action Navigate
Date url=[[WEBSITE]]

The replacement parameter “[[WEBSITE]]” will make a little more sense in a second! We are going to pass this from some JavaScript on the CRM form into this action!!

Step Three – Create an Event.

The final piece within USD will be to create a custom event that will call the action we created in step two. We wish to call this action whenever the website changes in our account tab. So we will need a new event on the account hosted control.

So open your account hosted control and navigate to events.

Then select the ADD NEW EVENT button, and simply give your event the name “AccountWebsiteOnChange“. Having saved your new event, you will then attach the action created in step two. So that your new event looks like this;

Step Four – On CRM form, add some JavaScript to call the event.

With your USD change complete you can turn your attention to the CRM form. So load CRM, find the customizations open under settings and open your account entity. The open the main account form.

At this point I am assuming you understand the basics of adding JavaScript to a CRM forms OnChange event.

In my simple example I triggered the following JavaScript in the OnChange event of the websiteurl field on my account entity.

function onChange_Website () {

  // *** Ensure website is a fully qualified address
  // ** So that USD doesn't try to add server and or to address!
  var website = Xrm.Page.getAttribute("websiteurl").getValue();
  if(website.substring(0, 4) != "http") {
    website = "http://" + website

  // *** If I am in USD then fire a USD event!
  if(window.IsUSD == true) {"http://event/?eventname=AccountWebsiteOnChange&WEBSITE=" + website);

Some things to note about this code ….

  1. I found that USD would automatically prefix any relative url with my CRM server name and organisation. To avoid this, I added a simple line of code to prefix the website name with “http” if it hadn’t been added.
  2. I only wanted my code to be triggered when running the CRM form from within USD. For this we use the window.IsUSD command. As it will return true if the CRM form has been rendered in a USD tab. This is important assuming you want your CRM forms to continue to operate correctly outside of USD.
  3. Finally, I needed a command to fire my USD event.“http://event/?eventname=AccountWebsiteOnChange&WEBSITE=” + website);

    Hopefully you can see my event name is AccountWebsiteOnChange. Then I have added a parameter called WEBSITE, which I have set to the value entered in the websiteurl field on my CRM form.


Once completed I published the change I’d made to my CRM form and testing it within USD. As soon as I entered / changed the website on my account form a tab appears in USD containing that site.

Clicking on the tab revealed the website that matched the one I’d entered.

I hope this simple example has shown you how to create a custom event in Unified Service Desk and call it from JavaScript on your CRM form. Hopefully you will find this a useful feature. J

One thought on “USD – Call Events from JavaScript

  1. Pingback: USD – The Book | Microsoft Dynamics CRM and Unified Service Desk

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s