2013-05-18 30 views
0

我试图从Microsoft Dynamics CRM 2011中的HTML页面启动一个对话框,说实话,我没有得到它的任何地方。获取HTML页面中的当前用户ID和服务器URL - CRM 2011

这是我的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编程是我以任何方式最强的天赋,所以任何人都可以提供任何建议,我怎么能解决这个问题?

+1

此页面是crm中的一个web资源?我没有看到对ClientGlobalContext.js.aspx的引用 –

回答

1

由于Guido说我相信你需要对ClientGlobalContext.js.aspx的引用。这是描述GetGlobalContext()的MSDN article。这里是它提到的地方包括对它的引用。

当您需要表单之外的上下文信息时,请在HTML Web资源中包含对ClientGlobalContext.js.aspx页面的引用。