I have some java script that I need to check the current user id in. I have read the posts that I have found on this site and I can not get them to work. Here is what I currently have:
function FormOpenPromt() {
var context = Xrm.Page.context;
var UserID = context.getUserId();
alert(UserID);
//*****
var oXmlHttp = new ActiveXObject(“MSXML2.XMLHTTP”);
oXmlHttp.open(“POST”, “/mscrmservices/2007/crmservice.asmx”, false);
oXmlHttp.setRequestHeader(“Content-Type”, “text/xml”);
oXmlHttp.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/crm/2007/WebServices/Execute”);
var Env = “”;
Env += “<soap:Envelope xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance’ “;
Env += “xmlns:xsd=’http://www.w3.org/2001/XMLSchema’ xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/’>”;
Env += GenerateAuthenticationHeader();
Env += “<soap:Body>”;
Env += “<Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>”;
Env += “<Request xsi:type=’WhoAmIRequest’ />”;
Env += “</Execute>”;
Env += “</soap:Body>”;
Env += “</soap:Envelope>”;
oXmlHttp.send(Env);
var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async = false;
xmlDoc.loadXML(oXmlHttp.responseXML.xml);
var userId = xmlDoc.getElementsByTagName(‘UserId’)[0].childNodes[0].nodeValue;
var userName = xmlDoc.getElementsByTagName(‘UserId’)[0].childNodes[0].getAttribute('name');
//****
if (Xrm.Page.getAttribute("po_callersname").getValue() == null) {
alert("Hello and thank you for calling GWG Life Settlements. Could I please have your name so I can properly address you?");
Xrm.Page.getAttribute("subject").setValue("TTC Lead");
}
}
The lines between the //*** is what I pasted in and it errors out. Can someone please help. All I am looking to do is return the current user's name. This also has to work on a new record, since I am want to use it on the form load of a new record.
Thanks, Dale