Tuesday, October 13, 2009

UserId of the Calling User in MS CRM 4.0

function GetCurrentUserInfo() {
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
var soapBody = "<soap:Body>" +
"<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<Request xsi:type='WhoAmIRequest' />" +
var soapXml = "<soap:Envelope " +
"xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
soapXml += GenerateAuthenticationHeader();
soapXml += soapBody;
soapXml += "</soap:Envelope>";
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
var userid = xmlDoc.getElementsByTagName("UserId")[0].childNodes[0].nodeValue;

return userid;


Dynamics CRM said...

Does this work for IFD?

Chandan said...

Thanks for your comment. I am sorry for the late reply.
I haven’t tried in IFD environment. Let me try this in IFD and if any changes will be needed, I’ll update you on the same.

Chandan said...

Yes. this method does work in IFD as well.