USD – A simple Scriptlet.

Unified Service Desk and CRM are both highly configurable meaning we can achieve great results without having to resort to code BUT sometimes you’ll want to inject code into you applications to make them behave in a specific manner. If you are familiar with CRM your probably already familiar with how to add JavaScript to CRM forms but what-if you’d like to do something similar with USD?

USD supports the ability to create scriptlets and call them from actions. A scriptlet can be used to inject JavaScript or .net code, in the interest of keeping this example simple I’ll show you how to add some JavaScript.

First off, two apologies!

  1. I am going to assume here you understand JavaScript and have a reasonable understanding of USD. Hopefully true if your attempting scripting within USD.
  2. Sorry, my example is fishing related. Again!

The Problem: I want to go fishing this weekend but would like to check the weather for the locations I want to fish. I can already open each location in a USD session and I know how to create a hosted control to show an external webpage but how to I construct the url to display the weather for the specific location???

The Solution: Call a scriptlet that will look at the fishing location, extract the postcode and construct a url suitable to display the weather from BBC website. Then use the output of that scriptlet in an action to display that website. Easy? (Actually it is!)

Before I show you the process, lets look at the final solution.

Below you can see I have a session open looking at a campsite called Hopleys. This is a small campsite not far from my house, they have a great bar and pizzeria for the evening! They also have a small fishing lake, which interests me. You can see I’ve created a toolbar button called “Local Weather”, clicking that will help me decide it a trip is worth considering.


Ooooops! You can see below that there is a weather warning at Hopleys, maybe I need to think again.


So how did I do this? The steps involved are;

  1. Create a scriptlet.
  2. Created a hosted control to hold the webpage and toolbar with a button to display. (I’ll assume you already know how to do this.)
  3. On the action on the toolbar button call the scriptlet to show the weather.

Step One – Create Scriptlet

Navigate to unified service desk in settings, then select the Scriplets option. And create a scriptlet like the one below.

I’m not trying to teach you JavaScript here! But to explain a little, I found to make the bbc site display the weather for a postcode I needed supply just the first section of the postcode and it needed to be lowercase.

ONE line of code is important to notice!

var postcode = “[[new_fishinglocation.new_postcode]+]”;

This sets a variable called postcode to the postcode form the entity that holds my fishing locations. The “+” is very important, I found the script failed without it. The meaning of the + is that nulls are handled. A null postcode would return an empty string not an error. Despite all my locations already having a postcode the “+” was essential.


Step Two – Create hosted control, toolbar etc

Next the step I won’t describe in full, as I’ll assume you’ve already got this nailed.

Create a hosted control to show a standard web application and then create a toolbar.

My toolbar is shown below and you can see I have created a button called “Local Weather”.


Step Three – Call the Scriptlet

On the local button I will need two actions, one to define and the local weather will display in an appropriate hosted control and the other to show the tab. (Again, I assume you’ve got this bit covered.)


But lets have a look at the action to show the weather, as that calls the scriptlet.


The line that interests us is url=[[$scriptlet.GetWeather]] this calls the script that we wrote in step one. Simple.

Obviously this is just an example, you’ll find and implement many more useful features than this. But if you like the concept of checking the weather at a given location you could always add similar logic to contacts or accounts.

9 thoughts on “USD – A simple Scriptlet.

  1. Hi Neil and congratulations for that great articles. Is it possible to inject .net code with scriptlets in USD? I have not found any examples in the SDK.


      • Hi Neil,

        How do we assign Postcode through the sample hosted application to the BBC site ? Do I need to set it in context in the sample hosted applicaton?


      • Hi,

        In my example, the line of code that inserts the postcode is

        var postcode = “[[new_fishinglocation.new_postcode]+]”;

        It might help to explain this is terms of a standard CRM entity. So assume you have a contact loaded and wanted a line of code to “grab” the post code from address 1. You’d do it like this ….

        var postcode = “[[contact.address1_postalcode]+]”;

        Hope this makes sense.

        Thanks for the message.

        Liked by 1 person

  2. Pingback: USD – LinkedIn | Microsoft Dynamics CRM and Unified Service Desk

  3. Pingback: USD – LinkedIn - Microsoft Dynamics CRM Community

  4. 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 )

Connecting to %s