Having added the ability to view and search for LinkedIn profiles in Unified Service Desk (USD), my thoughts turned to Twitter. I wanted to be able to generate and send tweets from within CRM / USD with a record of the tweets logged against the entity they were regarding. I might (for example) want to send a tweet when a case is opened to tell all of my followers about a known issue and to also tweet again when it is resolved. Or maybe I want to tweet each time a new customer is signed up. Etc.

The steps involved were more complicated than LinkedIn integration!

I hit a few snags along the way. Firstly twitter cannot be shown in an iframe within a CRM form. (Or at least I couldn’t get that working.) And when I showed Twitter in a tab I got script errors from the Twitter site. Which when I found were known problems with earlier versions of IE. Seemed the Internal WPF forms in USD can’t display Twitter without giving these error. But have several hours of playing I found an approach that worked.

Here is how I achieved the final working solution …

  1. I created a custom entity in CRM as an activity, called tweet.
  2. I created a hosted control called “Twitter”, to hold my new CRM entity.
  3. I created a hosted control called “Tweet”.
  4. I created a sciptlet to build a url.
  5. I created an action to navigate to the url.
  6. I created a navigation toolbar for the twitter hosted control.
  7. I added a button to the navigation toolbar.
  8. I created some Windows Navigation Rules to open my twitter hosted control.
  9. I tested my solution!

Step One – Create a custom entity in CRM as an activity, called tweet.

First off I created a custom entity as an activity within CRM. I also found a couple of icons for Twitter and set these on my entity. (Quick Google search and you’ll find similar icons!)

I then added a few custom fields to the activity.

“http”, this is a text field of type url. If the tweet references a link to a website then that will be entered here.

“hashtags”, any hashtags to be added to the tweet will be listed here. The hashtags don’t need the user to key in the # character! But my code copes with it being keyed or not.

My form looked like this ….

So far a pretty standard CRM change.

Step Two – Create hosted control called “Twitter”, to hold my new CRM entity.

Next I needed a hosted control in USD that will be the container for my newly created twitter entity. This was pretty standard, the USD component type is “CRM Page” and display panel is “MainPanel”.

Step Three – Create a hosted control called “Tweet”.

Next I needed a hosted control that will be the tab needed to show the twitter website. It should have been a standard website. But that didn’t work. As I explained in my opening paragraph. I ended up trying something which works but I think should be wrong! I defined this hosted control as a CRM Page even though I’m going to display an external website in the tab.

A standard webpage with either “Internal WPF” or “IE” as the hosting type did not work!

Step Four – I created a scriptlet to build a url.

Now I needed to create some JavaScript code that will build an appropriate URL to create the tweet. My code is below;

function Tweet() {

var url;

var text = "[[new_tweet.subject]+u]";

var http = "[[new_tweet.new_http]+u]";

var hashtags = "[[new_tweet.new_hashtags]+u]";

var textEncoded = encode(text);

url = "https://twitter.com/intent/tweet?text=" + textEncoded

if (http != null && http != "") {

var httpEncoded = encode(http)

url = url + "&url=" + httpEncoded;


if (hashtags != null && hashtags != "") {

hashtags = hashtags.replace("#", "");

var hashtagsEncoded = encode(hashtags);

url = url + "&hashtags=" + hashtagsEncoded;


return url;


function encode(value) {

value = value.replace(":", "%3A");

value = value.replace(" ", "%20");

value = value.replace("/", "%2F");

value = value.replace("#", "%23");

value = value.replace(",","%2C");

value = value.replace("@", "%40");

value = value.replace("?", "%3F");

return value;



I ended up with a scriptlet called “Twitter” that looked like this.

Step Five – I created an action to navigate to the url.

Next I created an action that will use my scriptlet and load twitter in the “Tweet” tab. For this the hosted control was “tweet”, the one I’d just created. The action is “Navigate”, then the data portion contains the line “url=[[$scriptlet.twitter]]”, this simply calls my scriptlet which returns the correct url.

Step Six – Create a navigation toolbar for the twitter hosted control.

Below you can see I created a toolbar called “Twitter Navigation Toolbar”, once saved I used the “Hosted Controls” option to link this toolbar to my hosted control called “Twitter”. (The one containing the CRM page for my custom activity.)

Step Seven – Add a button to the navigation toolbar.

I then created a toolbar button and added the action I’d already created. Notice that I have re-used the 32×32 icon I’d assigned to my tweet entity. The showtab needs to be “Tweet” as this is the tab you’ll want to give focus to after clicking the tweet button. I have also added a condition for “enabled” and “visibility”. [[new_tweet.subject]] The effect of doing this means the tweet button isn’t shown until the tweet has been saved in CRM. The user will need to create and save the tweet activity, before they actually send it.

Step Eight – Create some Windows Navigation Rules to open my twitter hosted control.

Next I created several windows navigation rules, these were for each of the session types I wanted to enable tweets in. My solution makes use of most of the CRM standard entities, so I created rules for contact, lead, account, case, opportunity etc etc. Your list may be shorter. Each one will require a similar rule. All the rule is saying is that when a user creates (or opens) a tweet activity from an entity open the tab in that session.

Field Description
Name Can be anything (so, “Twitter from Contact” etc)
Order Mandatory field, I set all of mine to 1.
From The entity you are calling Twitter from. Contact in this example.
Entity This is the schema name of the entity you are called. “new_tweet” in this example. Note: This won’t initially exist, you’ll need to add it when you create your first navigation rule.
Route Type In Place
Action Route Window
Destination Tab
Target Tab Twitter (The hosted control we want to load.)
Show Tab Same as target tab!
Hide Command Bar Needs to be “No” as we want to be able to save the tweet!
Hide Navigation Ba This isn’t required, so set to “Yes”.

Step Nine – I tested my solution!

WARNING: My testing / debugging actually took quite a long time! As I had the problems I described in my opening paragraph. Hopefully your testing will be simpler / quicker.

Because I had added “Tweet” as an activity it was available in the social pan of all the entities I needed to tweet from!

Selecting “Tweet” from the social pane opens a Twitter tab. And once you save the tweet the “bird” icon appears to allow you to send. My tweet tab looked like this …..

Clicking the “bird” loads the page shown below. Note, that here I am already logged into twitter. If you aren’t logged in you will be able to enter you credentials on this page. And obviously when you click the blue tweet button your tweet is sent.