I am trying to use the code below I found in another thread to get the Current User who is logged in, not the Owner of the record. Does anyone know how I can tweak the code below to change this? I tried replacing the references to "ownerid" with Xrm.Page.context.getUserId(), but I have not had any luck. I am not sure how to return the GUID from the getUserId() method to be able to use it. I imagine it has to do with arrays, but this is a new concept to me. Thanks for any and all your help!
function GetCurrentUserTeams() { debugger; var lookup = Xrm.Page.getAttribute("ownerid").getValue(); var OwnerID; var OwnerName; if (lookup != null && lookup[0] != null) { OwnerName = lookup[0].name; OwnerID = lookup[0].id; } var xml = "" +"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +"<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\">" + GenerateAuthenticationHeader() +" <soap:Body>" +" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +" <q1:EntityName>team</q1:EntityName>" +" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +" <q1:Attributes>" +" <q1:Attribute>name</q1:Attribute>" +" </q1:Attributes>" +" </q1:ColumnSet>" +" <q1:Distinct>false</q1:Distinct>" +" <q1:LinkEntities>" +" <q1:LinkEntity>" +" <q1:LinkFromAttributeName>teamid</q1:LinkFromAttributeName>" +" <q1:LinkFromEntityName>team</q1:LinkFromEntityName>" +" <q1:LinkToEntityName>teammembership</q1:LinkToEntityName>" +" <q1:LinkToAttributeName>teamid</q1:LinkToAttributeName>" +" <q1:JoinOperator>Inner</q1:JoinOperator>" +" <q1:LinkCriteria>" +" <q1:FilterOperator>And</q1:FilterOperator>" +" <q1:Conditions>" +" <q1:Condition>" +" <q1:AttributeName>systemuserid</q1:AttributeName>" +" <q1:Operator>Equal</q1:Operator>" +"<q1:Values>" + //code to get the owner "<q1:Value xsi:type=\"xsd:string\">" + OwnerID + "</q1:Value>" +"</q1:Values>" +" </q1:Condition>" +" </q1:Conditions>" +" </q1:LinkCriteria>" +" </q1:LinkEntity>" +" </q1:LinkEntities>" +" </query>" +" </RetrieveMultiple>" +" </soap:Body>" +"</soap:Envelope>" +""; 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; //alert(resultXml.xml); // Save all entity nodes in an array. var entityNodes = resultXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity"); var teamnames = new Array(); var teamids = new Array(); for (var i = 0; i < entityNodes.length; i++) { var entityNode = entityNodes[i]; var teamidNode = entityNode.selectSingleNode("q1:teamid"); var teamNode = entityNode.selectSingleNode("q1:name"); var teamid = (teamidNode == null) ? null : teamidNode.text; var team = (teamNode == null) ? null : teamNode.text; teamnames[i] = team; teamids[i] = teamid; } alert(teamnames); }