Click here to Skip to main content
6,594,932 members and growing! (15,288 online)
Email Password   helpLost your password?
Desktop Development » Desktop Gadgets » General     Intermediate

Microsoft Dynamics CRM Vista Sidebar Gadget

By John Straumann

Accessing Microsoft Dynamics CRM information from a Sidebar Gadget
C#, Javascript, .NET, Vista, Visual Studio, Dev
Posted:27 Mar 2007
Views:47,496
Bookmarked:38 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 3.77 Rating: 4.18 out of 5

1

2
3 votes, 37.5%
3

4
5 votes, 62.5%
5
Screenshot - 2_small.jpg

Introduction

Microsoft Dynamics CRM is a powerful program, and what sets it apart from the many other choices in the CRM application space is its tight integration to the Microsoft platform. When Vista shipped, I immediately started looking for new and exciting ways to demonstrate the value of Microsoft CRM and the Microsoft platform, and the first interesting area I discovered is gadgets. Being a true propeller head, my favorite gadget is the CPU utilization meter, and I also love the pictures slideshow gadget. I decided to create a gadget that can display the accounts and contacts from Microsoft Dynamics CRM on the user desktop.

Note that this article assumes familiarity with developing gadgets for Windows Vista. If you're new to gadgets, I suggest first reading the article: http://microsoftgadgets.com/Sidebar/DevelopmentOverview.aspx

About CRM and the gadget

While a properly implemented CRM system can be a very powerful tool, a complaint heard often is that there is so much information in the system, it is impossible to make any sense of it. The tools provided with Microsoft CRM can be designed so that the users can quickly access the important information stored in the system, and the MSCRM gadget is designed to make this process even faster.

The gadget displays the list of accounts and contacts associated with the currently logged on user (made possible by MSCRM's integration with Active Directory) and then if the user clicks an item in the list, the MSCRM record will load in a browser window.

Please note that in order to use this gadget, you must have access to a functioning MSCRM installation, and you must know the URL of your MSCRM server.

Using the code

The code itself consists of three HTML files: index.htm, accounts.html, and contacts.html. The working machinery is all JavaScript, made possible by JavaScript's ability to instantiate and access ActiveX objects. The index.html file uses JavaScript to implement a tabbed interface, one tab for Accounts, one tab for Contacts.

// Index.html

// The JavaScript for the tabs

<script type="text/javascript">
var stl=""
var bChecked=false
function handlelink(aobject)
{
  stl=aobject.href
  bChecked=(document.tabcontrol && document.tabcontrol.tabcheck.checked)? true : false
  if (document.getElementById && !bChecked)
  {
    var theTab=document.getElementById("tablist")
    var theTablinks=theTab.getElementsByTagName("A")
    for (i=0; i<theTablinks.length; i++)
      theTablinks[i].className=""
    aobject.className="current"
    document.getElementById("tabiframe").src=stl
    return false
  }
  else
    return true
}
</script>

Microsoft Dynamics CRM provides a very powerful web services API which provides access to the underlying system. So the basic idea behind this gadget was to instantiate a Microsoft.XMLHTTP ActiveX object, and then use that object to call into the MSCRM web services to retrieve the account and contact information. The challenge is that the call is not as simple as a SQL query like "select * from Accounts". We need to build an actual SOAP message. In order to do this I cheated a bit and enabled logging on my MSCRM server, made a call to the web services to retrieve the accounts and contacts, and then parsed the resulting log file to find the call I needed. For those interested, the log file is included with the downloadable source files for this project.

I then built the message thus:

// Accounts.html

// The JavaScript to build the SOAP message


// The following line must be changed to match the users MSCRM server URL

var serverUrl = "http://danubecrm:5555/mscrmservices/2006";

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", serverUrl + "/crmservice.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
xmlhttp.setRequestHeader("SOAPAction", 
    "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple")
xmlhttp.send("<?xml version='1.0' encoding='utf-8'?>"+"\n\n"+"<soap:Envelope"+
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'+
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
' xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
' <soap:Body>' +
' <query xmlns:q1=http://schemas.microsoft.com/crm/2006/Query 
' xsi:type="q1:QueryExpression" xmlns="http://schemas.microsoft.com/crm/2006/WebServices">'+
' <q1:EntityName>account</q1:EntityName>' +
' <q1:ColumnSet xsi:type="q1:ColumnSet">' +
' <q1:Attributes>' +
' <q1:Attribute>accountid</q1:Attribute>' +
' <q1:Attribute>name</q1:Attribute>' +
' </q1:Attributes>' +
' </q1:ColumnSet>' +
' <q1:Distinct>false</q1:Distinct>' +
' </query>'+
' </soap:Body>'+
' </soap:Envelope>')

The next step is to parse the XML returned by the CRM web services call and separate the returned entities. The code below also prints out the returned entities inside HTML anchors so they are clickable.

var result = xmlhttp.responseXML.xml;
var BEs= result.split("<BusinessEntities>");
var BE = BEs[1].split("<BusinessEntity");
for (i = 0; i < BE.length; i++)
{
firstname = BE[i].indexOf("<name>")+6;
secondname = BE[i].indexOf("</name>");
firstid = BE[i].indexOf("<accountid>")+11;
secondid = BE[i].indexOf("</accountid>");
  if (BE[i].substring(firstid,secondid).length > 0 )
  {
    // The URL below must also be changed to the users MSACRM server URL

    document.writeln("<a href=\"http://danubecrm:5555/sfa/accts/edit.aspx?id=" + 
    BE[i].substring(firstid,secondid) + "\" target=\"new\"><font size=\"2px\"" +
    "name=\"verdana\">" + BE[i].substring(firstname,secondname) + "</font></a><BR>");
  }
} 

The body of the Accounts.html file is straightforward, we must call the JavaScript function we created. I called my function AccessCrmWebServices() but of course the name does not matter.

<body bgcolor="#eff3f7">
<script language="JavaScript" type="text/javascript">
AccessCRMWebServices() ;
</script>
</body> 

And that's pretty much it! Now we just deploy the gadget files to the Vista machine as described in the overview article referenced in the beginning of this article, and the gadget will be available.

History

  • v1: March 26, 2007

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

John Straumann


Member

Location: Canada Canada

Other popular Desktop Gadgets articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
GeneralHelp with Access Denied message Pinmembercenvia200210:17 23 Mar '09  
GeneralRe: Help with Access Denied message Pinmembercenvia200210:35 23 Mar '09  
GeneralMentioned in the book PinmemberDeepWaters9:59 17 Dec '08  
Generalaccess problem in sidebar (msxml3.dll) Pinmembermrv797:54 27 Oct '08  
QuestionCRM 4.0 changes? PinmemberMember 36421127:49 8 May '08  
AnswerRe: CRM 4.0 changes? PinmemberJohn.Straumann13:01 31 May '08  
AnswerRe: CRM 4.0 changes? PinmemberMember 32068275:12 1 Dec '08  
GeneralVery nice article PinmemberQuartz.10:36 3 Sep '07  
GeneralHelp for CRM Vista Gadget install PinmemberHans Veldman21:43 28 Jun '07  
General0x80040216 soap:Server Server was unable to process request Pinmemberinferano1:16 22 Jun '07  
GeneralWhat about operators PinmemberGorillaman15:27 3 Apr '07  
GeneralRe: What about operators PinmemberJohn Straumann15:45 3 Apr '07  
GeneralRe: What about operators PinmemberGorillaman15:52 3 Apr '07  
GeneralRe: What about operators PinmemberGorillaman15:54 3 Apr '07  
Generalsystem is undefined Pinmemberphgordon6:28 28 Mar '07  
AnswerRe: system is undefined PinmemberJohn Straumann8:44 28 Mar '07  
GeneralRe: system is undefined Pinmembertwinsen835:44 21 May '07  
GeneralRe: system is undefined PinmemberJohn Straumann9:34 21 May '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Mar 2007
Editor: Deeksha Shenoy
Copyright 2007 by John Straumann
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project