Firstly i’d like to thank Michael Höhne for his great application that converts your c# code to Javascript. Basically you input your c# code and it sends a soap request and gets a reply and converts the request to Javascript so you can do it in realtime and not by a plug-in.

  • First grab the application from: http://mscrmblog.net/downloads/JSWebCall.zip
  • Open the project Visual Studio and double click on Form1.cs
  • Go to the “try” line and input your c# code to be converted.
  • Below i have my peice of code which just queries the systemuser entity for the GUID: F2EBE1D4-8E57-DD11-9225-000C29165D7E

  • Build the program and run the Application (from the bin\deubg dir)
  • Click on the start and wait until you see a response in the response tab.
  • Then move onto the Javascript tab and copy the code and paste it on a event (onchange, onload & onsave)
  • Heres my final code:
window.setTimeout(RetrieveXML,1000);
function RetrieveXML()
{
var xml = "" +
"" +
"" +
GenerateAuthenticationHeader() +
" " +
" " +
" " +
" systemuser" +
" " +
" " +
" businessunitid" +
" " +
" " +
" false" +
" " +
" And" +
" " +
" " +
" systemuserid" +
" Equal" +
" " +
" "+crmForm.all.ownerid.DataValue[0].id+"" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;
var businessUnitName = resultXml.getElementsByTagName("q1:businessunitid")[0].getAttribute('name');
alert(businessUnitName);
}

  • Basically this gets the businessunit name from the ownerid in the field.

Hope this helps.