CRM 4.0得到用户个人信息
//-------------- //返回当前用户ID //-------------- function GetCurrentUserId() { var soapBody = "<soap:Body><Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'><Request xsi:type='WhoAmIRequest' /></Execute></soap:Body>"; var soapXml = "<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'>"; var header1 = GenerateAuthenticationHeader(); soapXml += header1; soapXml += soapBody; soapXml += "</soap:Envelope>"; 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"); xmlhttp.send(soapXml); xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.loadXML(xmlhttp.responseXML.xml); var userid = xmlDoc.getElementsByTagName("UserId")[0].childNodes[0].nodeValue; return userid; } //---------------- //返回当前用户角色 //---------------- function GetCurrentUserRoles() { 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>role</q1:EntityName>" + " <q1:ColumnSet xsi:type=\"q1:AllColumns\" />" + " <q1:Distinct>false</q1:Distinct>" + " <q1:LinkEntities>" + " <q1:LinkEntity>" + " <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" + " <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" + " <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" + " <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" + " <q1:JoinOperator>Inner</q1:JoinOperator>" + " <q1:LinkEntities>" + " <q1:LinkEntity>" + " <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" + " <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" + " <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" + " <q1:LinkToAttributeName>systemuserid</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>" + " <q1:Value xmlns:q2=\"http://microsoft.com/wsdl/types/\" xsi:type=\"q2:guid\">"+GetCurrentUserId()+"</q1:Value>" + " </q1:Values>" + " </q1:Condition>" + " </q1:Conditions>" + " </q1:LinkCriteria>" + " </q1:LinkEntity>" + " </q1:LinkEntities>" + " </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; var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.loadXML(xmlHttpRequest.responseXML.xml); var lineCount=xmlDoc.getElementsByTagName("q1:name").length; var resultValue=''; for(var i=0;i<lineCount;i++) { resultValue +=xmlDoc.getElementsByTagName("q1:name")[i].childNodes[0].nodeValue+'_'; } return resultValue; } //-------------------- //返回当前用户的用户名 //-------------------- function GetCurrentUserName() { 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:QueryByAttribute\">"+ " <q1:EntityName>systemuser</q1:EntityName>"+ " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">"+ " <q1:Attributes>"+ " <q1:Attribute>fullname</q1:Attribute>"+ " </q1:Attributes>"+ " </q1:ColumnSet>"+ " <q1:Attributes>"+ " <q1:Attribute>systemuserid</q1:Attribute>"+ " </q1:Attributes>"+ " <q1:Values>"+ " <q1:Value xsi:type=\"xsd:string\">"+GetCurrentUserId()+"</q1:Value>"+ " </q1:Values>"+ " </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; var resultValue=resultXml.getElementsByTagName("q1:fullname")[0].childNodes[0].nodeValue; return resultValue; }
posted on 2011-07-18 11:50 HelloHongfu 阅读(276) 评论(0) 编辑 收藏 举报