在MSCRM 4.0中查找当前登录用户 [英] Finding Currently Logged on User in MSCRM 4.0

查看:87
本文介绍了在MSCRM 4.0中查找当前登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发MS CRM 4.0(RTM)。

We are working on MS CRM 4.0 (RTM). 

我们有一个要求,在点击自定义按钮(通过ISV.CONFIG创建)时,我需要找到当前登录用户的用户ID并将其作为查询字符串传递到其中一个URL。

We have a requirement wherein, on click of a custom button (created through ISV.CONFIG), I need to find the currently logged in user's userid and pass it as a querystring to one of the URL.

我尝试了以下Javascript代码,但是它会引发错误...

I tried the following Javascript code, but it throws an error...

//发一个我要求的人
var whoAmIRequest = new RemoteCommand(" SystemUser"," ; WhoAmI"," / MSCRMServices /");
//执行命令并获取响应
var response = command.Execute();
//从响应xml中获取用户ID
var userIdString = response.Xml.text;

//make a who am i request
var whoAmIRequest = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
//execute the command and obtain a response
var response = command.Execute();
//get the user id from the response xml
var userIdString = response.Xml.text;

alert(userIdString);

alert(userIdString);

这方面的任何帮助都非常有用,非常感谢。

any help in this regard is very helpful and greatly appreciated.

谢谢!!!

推荐答案


< br>尝试这个...
函数GetCurrentUserInfo()
{

var SERVER_URL =" http:// crm:5555" ;; //替换你的crm服务器名称

var xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP");

xmlhttp.open(" POST",SERVER_URL +" / 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'/>" +

"< /执行>< / soap:Body>" ;;


var soapXml ="< soap :信封" +

" xmlns oap ='http:// schemas .xmlsoap.org / soap / envelope /'" +

" xmlns:xsi ='http://www.w3.org/2001/XMLSchema-instance'" +

" xmlns:xsd ='http://www.w3.org/2001/XMLSchema'>" ;;

soapXml + = GenerateAuthenticationHeader();

soapXml + = soapBody ;

soapXml + ="< / soap:Envelope>" ;;

xmlhttp.send(soapXml);

xmlDoc = new ActiveXObject(&x ; Microsoft.XMLDOM");

xmlDoc.async = false;

xmlDoc.loadXML(xmlhttp.responseXML.xml);

var userid = xmlDoc.getElementsByTagName(" ; UserId")[0] .childNodes [0] .nodeValue;

// var buid = xmlDoc.getElementsByTagName(" BusinessUnitId")[0] .childNodes [0] .nodeValue;
< br> // var orgid = xmlDoc.getElementsByTagName(" OrganizationId")[0] .childNodes [0] .nodeValue;

return userid;

// alert(" UserId: " + userid +&quo t; \r\\\
BusinessUnitId:" + buid +" \\\\ nOrganizationId:" + orgid);

}
Hi,

Try this...
function GetCurrentUserInfo()
{

var SERVER_URL = "http://crm:5555"; //replace with your crm server name

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

xmlhttp.open("POST", SERVER_URL + "/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' />"+

"</Execute></soap:Body>";


var soapXml = "<soap:Envelope " +

"xmlnsoap='http://schemas.xmlsoap.org/soap/envelope/' "+

"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "+

"xmlns:xsd='http://www.w3.org/2001/XMLSchema'>";

soapXml += GenerateAuthenticationHeader();

soapXml += soapBody;

soapXml += "</soap:Envelope>";


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;

//var buid = xmlDoc.getElementsByTagName("BusinessUnitId")[0].childNodes[0].nodeValue;

//var orgid = xmlDoc.getElementsByTagName("OrganizationId")[0].childNodes[0].nodeValue;

return userid;

//alert("UserId: " + userid + "\r\nBusinessUnitId: " + buid + "\r\nOrganizationId: " + orgid);

}


这篇关于在MSCRM 4.0中查找当前登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆