First off, two apologies!
- 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;
- Create a scriptlet.
- 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.)
- 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.
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.