[英]Get Id of user currently logged into MS Dynamics CRM 2011 Online
[英]Get The Current User ID and Server URL in an HTML Page - CRM 2011
我正在尝试从Microsoft Dynamics CRM 2011中的HTML页面启动对话框,老实说,我对此一无所知。
这是我的HTML页面:
<HTML><HEAD>
<META charset=utf-8>
<SCRIPT>
function getServerUrl(){
var context, crmServerUrl;
if (typeof GetGlobalContext != "undefined") {
context = GetGlobalContext();
}
else if (typeof Xrm != "undefined") {
context = Xrm.Page.context;
}
else {
throw new Error("CRM context is not available.");
}
if (context.isOutlookClient() && !context.isOutlookOnline()) {
crmServerUrl = window.location.protocol + "//" + window.location.host;
} else {
crmServerUrl = context.getServerUrl();
crmServerUrl = crmServerUrl.replace(/^(http|https):\/\/([_a-zA-Z0-9\-\.]+)(:([0-9]{1,5}))?/, window.location.protocol + "//" + window.location.host);
crmServerUrl = crmServerUrl.replace(/\/$/, ""); // remove trailing slash if any
}
return crmServerUrl;
}
function LaunchDialog()
{
var string = getServerUrl();
alert(string);
var url="/" + getOrg() + "/cs/dialog/rundialog.aspx?DialogId=%7b7B189BA4-84B4-4E41-AE85-2066A379E502%7d&EntityName=systemuser&ObjectId=" + getUser();
//window.open(url, "", "status=no,scrollbars=no,toolbars=no,menubar=no,location=no");
alert(url);
//window.open(url);
}
function getOrg() {
alert("Called");
///<summary>
/// get organisation
///</summary>
var Org = "";
if (typeof GetGlobalContext == "function") {
var context = GetGlobalContext();
Org = context.getOrgUniqueName();
}
else {
if (typeof Xrm.Page.context == "object") {
Org = Xrm.Page.context.getOrgUniqueName();
}
else
{ throw new Error("Unable to access Organisation name"); }
}
alert("About to return org");
return Org;
}
function getUser() {
alert("Called 1");
///<summary>
/// get logged in user
///</summary>
var User = "";
if (typeof GetGlobalContext == "function") {
var context = GetGlobalContext();
User = context.getUserId();
}
else {
if (typeof Xrm.Page.context == "object") {
User = Xrm.Page.context.getUserId();
}
else
{ throw new Error("Unable to access the UserId"); }
}
alert("End User");
return User;
}
</SCRIPT>
</HEAD>
<BODY contentEditable=true>
<H1>Create Record</H1>
<P><BUTTON onclick=LaunchDialog()>Try it</BUTTON></P></BODY></HTML>
无论如何,Web编程是我的最强才能,因此任何人都可以提供有关如何解决此问题的建议吗?
正如Guido所说,我相信您需要引用ClientGlobalContext.js.aspx。 这是描述GetGlobalContext()的MSDN文章 。 这里提到要包含对它的引用。
当您需要表单之外的上下文信息时,请在HTML Web资源中包括对ClientGlobalContext.js.aspx页面的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.