USD – Google Maps (using $Context)

Within Unified Service Desk(USD) I had a requirement to display Google maps to accounts, contacts and leads. I found that this was easier than I expected by using $Context.

If you don’t know $Context can be used with replacement parameters to get variables based on context. So when you are in a contact session (for example) you can use [[contact.fullname]] to return the fullname of a contact but also [[$Context.fullname]] would also return the fullname of the contact.

The “problem” with this is that the context can change, meaning “fullname” might not always be available. As if you happen to be looking at a case or account there would be nothing returned for “fullname”. As they don’t have that value. Because of this I tend to prefer to use the [[contact.fullname]] syntax when I want to be explicit on the value to return.

But with Goolge map integration $Context was very useful!

Account, contact and lead all contain a common name for their main address. So [[$Context.address1.postalcode]] will return valid results on them all. Meaning I only needed one hosted control and one action for all three.

The steps I followed were;

  1. Create a hosted control to display the maps.
  2. Create Scriptlet
  3. Create an action to display the maps.
  4. Create a navigation toolbar button for account, contact and lead to trigger the action.

Before I started I uploaded an icon (using customizations in CRM, to load it as a web resource) that I’d later use on my toolbars. The ICON I used was …

Other ICONS are available!!!

STEP ONE – Create a hosted control to display the maps.

My hosted control look like the one below.

Notice that the display name is “MAP [[$Context.address1_postalcode]+]”, this will name the tab including the postcode from which ever entity you are using. Meaning I can have one hosted control!

USD component type is “Standard Web Page”, as you’d expect. I opted to use IE as the hosting type.

And my tab is not global, as I want to show it in account, contact or lead sessions.

And display panel is “MainPanel”.

FYI: I did try RightPanel but felt that there simply wasn’t enough screen space to do justice to the map.

STEP TWO – Create a scriptlet

I choose to create a simple scriptlet to construct my url to load Google Maps. To be honest I could have probably constrcuted this straight in the action. BUT, I felt that having a scriptlet would make it easier for me to change in the future. Or maybe extend. For example: If I feel the need to add country or city into the url I can simply add this into my scriptlet.

Any way I created a scriptlet called, “GoogleMap” with the following code;

function GoogleMap() {

var postcode=”[[$Context.address1_postalcode]+]”

var url=”https://www.google.co.uk/maps/place/” + postcode;

return url

}

GoogleMap();

STEP THREE – Create an action to display the maps.

Next I needed (one) action to display the maps. Mine looked like the one below. It is a simple navigate action that calls the scriptlet I created in the previous step.

STEP FOUR – Create a navigation toolbar button for account, contact and lead to trigger the action.

I then added a toolbar button to the navigation toolbars I’d already created on account, contact and lead. As actually used there buttons as that fitted well with the UI I have created. But you could probably have just one button if you prefer.

You can see I added the action created in the previous step.

One tip here might be, add in a condition that will only enable and make the button visible if a postcode is present. Something like “[[$Context.adddress1.postalcode]]”!=”” would do the trick!

My button for account looks like this;

Finally here is how the map for my contact record looked in USD, enjoy …..

4 thoughts on “USD – Google Maps (using $Context)

  1. Pingback: Learning Unified Service Desk | Microsoft Dynamics CRM and Unified Service Desk

  2. Pingback: Bing Maps | Microsoft Dynamics CRM and Unified Service Desk

  3. Pingback: Bing Maps - 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:

WordPress.com Logo

You are commenting using your WordPress.com 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