One of the key benefits of having Unified Service Desk host web applications rather than just displaying them in an iframe within the web client is its inherent ability to perform bidirectional communication with the web application without modifying its source code. This is particularly important when you don't have control over the development of the application either because it is built by a 3rd party or another department. Even if you do have control, you'd have to figure out how to code your application differently depending on whether it is hosted within USD or not, which is not ideal. With an iframe, security limits you to pushing URL's, which is a very limited form of communication, unless the host and hosted applications can agree on a protocol such as the HTML 5 messaging protocol. These are fine methods when you have the ability to define both applications, but not so good when you need to communicate with an application that cannot or will not be so cooperative.
saved on a web form. You might also detect when data is changing in fields and fire an event up to USD to tell it about the new data and populate data parameters to share with other hosted controls.
// the web application does something here.
In my case, I still want the code inside MyButtonWasClicked() to run but I want USD to know when this function was called as well. What we want to do is insert USD into the logic on the page without disrupting it's functionality. To achieve this, we want to start by adding an action to the page's BrowserDocumentComplete or PageLoadComplete event in USD, whichever is appropriate.
<My Hosted Control>
var MyButtonWasClickedOld = MyButtonWasClicked; //save the old method
MyButtonWasClicked = function() // create a new version of the function
window.open("http://event/?eventname=buttonclickevent¶m1=value1"); // fire the event to USD
MyButtonWasClickedOld(); // call our old method
This action will replace the current implementation of the MyButtonWasClicked() function within the page and only when USD loads it. Outside USD, it will continue to work as it always has. When the user clicks the button, it will call the new version of the function and in this case will call window.open with a special syntax that I describe soon, followed by calling the old implementation of the function. In this case, we are notifying USD of the event before running the old implementation. You could easily reverse that behavior or even eliminate the old behavior if it was desired.
Window.open event syntax
When a page is requested that starts with the special syntax of http://event/?, USD interprets it as an event. This special URL must always have a parameter called eventname. This parameter indicates the name that will be used in the USD event configuration.
Now in CRM, lets add an event to our hosted control to do something with this event. Go to the Unified Service Desk events configuration link.
Click New to add a new event.
In the event's name, enter the name exactly the same as specified in the eventname parameter of the event URL.
The Hosted Application field should be populated with the hosted control that contains your web application that you injected the script and that will produce the event. You can then save this and add Action Calls to this event as you see fit. In this case, let's just plan to display the event parameter, param1, in a dialog box. Click Add to create a new action call within your new event.
CRM Global Manager
text=My parameter is [[param1]]
Now when you run Unified Service Desk and click the button within the web application, your event will be fired. You will see the event line in the USD Debugger as well so it's a good way to make sure your event is properly firing. Also, since your event is mapped to a configured USD event, your action call will run as well. The parameters you supplied in your event URL are all passed to the action calls linked to the event you created so you can use them when creating your action calls.
<My Hosted Control>
When you add this action call to your event, it will obtain the largeDataVariable and return it to the $Return entry in the Data Parameter list. This method can handle quite a large amount