Microsoft CRM 3.0 shipped with an extensive web service API that can be used by various types of applications. Here is a sample Windows sidebar gadget (or just gadget) that retrieves queue items related to the currently logged in user every predefined interval. Since the gadget is always available on the desktop but small in size, the ideal information to display on gadget should be something dynamic and concise. In Microsoft CRM context, the queue item entity fits squarely as it is changed quite frequently and requires immediate attention from a user.
The code is provided at http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=A6791FE6-5A4C-4432-8FBD-BBD8A499120B
Figure 1 "In progress" queue items
Figure 2 "Assigned" queue items
Figure 3 Settings window
For more information about developing gadget in general, please refer to MSDN article in the resource section. This article will focus more on CRM specific aspects.
Gadgets are composed of HTML and Jscript. We can use XmlHttp from JScript to send hand crafted SOAP message to the CRM server. Then we use an Msxml2.DOMDocument to parse the response to get the result. We need not do it asynchronously as the user is not blocked by the gadget anyway and it will be much more complicated to do it asynchronously.
In keeping with best practices, this sample retrieves only columns that are needed to reduce server load.
The gadget infrastructure provides a nice API for reading and writing settings. Be careful about storing sensitive information though. In this case, we just store the CRM server name, polling interval, and queue type so we are okay.
For reading settings
var currentServerName = System.Gadget.Settings.readString("crmServerName");
For writing settings
var temp = serverName.value;
Gadgets also subject to all sorts of cross site scripting vulnerabilities, since they are also web applications. All user input should be validated before using it. All external data (including data from the CRM server) must be properly encoded before rendering.
This sample utilizes template.css to make the gadget look consistent with the CRM web application. For example the server name label is shown as a required field. This template.css file is shipped with CRM SDK. You can download it from Microsoft.com.
Because this gadget is a real application though it looks cute; there will be a time that you will want to patch it after you ship. The best way to enable gadget patching is to deploy it with MSI. However, for simplicity of our sample, I just use the zip approach. All you need to do is zip all HTML, JScripts, CSS, and the manifest (gadget.xml) together and change the resulting file’s extension from .zip to .gadget. Then the user can install it by double clicking.
- MSDN Windows Sidebar Gadget Development Overview (http://msdn2.microsoft.com/en-us/library/aa965850.aspx)
- System.Gadget.Settings in MSDN (http://msdn2.microsoft.com/en-us/library/ms723661.aspx)
- Other CRM Windows sidebar gadgets
- CRM SDK (http://www.microsoft.com/downloads/details.aspx?familyid=9C178B68-3A06-4898-BC83-BD14B74308C5&displaylang=en).