Share via


GetGlobalContext function and ClientGlobalContext.js.aspx(客户端引用)

 

发布日期: 2016年11月

适用于: Dynamics CRM 2015

当使用 Web 资源编程时,使用 GetGlobalContext 函数 可以获得上下文信息的访问权限。 若要在 HTML Web 资源中获取 GetGlobalContext 函数,包含对 ClientGlobalContext.js.aspx 的引用。

GetGlobalContext 函数

GetGlobalContext 函数返回的上下文对象与 Xrm.Page.context 中存在的上下文对象相同。

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

以下示例演示在用于窗体脚本或与 HTML Web 资源联用的脚本时,将显示为返回上下文对象而设计的函数。

function _getContext() {
 var errorMessage = "Context is not available.";
 if (typeof GetGlobalContext != "undefined")
 { return GetGlobalContext(); }
 else
 {
  if (typeof Xrm != "undefined") {
   return Xrm.Page.context;
  }
  else { throw new Error(errorMessage); }
 }
}

ClientGlobalContext.js.aspx

如果将引用列入 Web 资源目录根处的 ClientGlobalContext.js.aspx 页面,则您可以使用 GetGlobalContext 函数。

备注

如果您在 HTML Web 资源名称中不使用反斜线字符来模拟文件夹结构,则您可以使用以下脚本元素将脚本列入您的页面:<script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
如果您正在 HTML Web 资源名称中使用反斜线字符来模拟目录结构,则您必须在脚本元素对其进行反映。 以下示例为名称为‘sdk_/Contoso.htm’的 HTML Web 资源和名称为‘sdk_/Scripts/ContosoScript.js’的 JScript Web 资源(具有名称为‘sdk_/Styles/ContosoStyles.css’的 CSS Web 资源)。

<head>
    <title>HTML Web Resource</title>
    <script src="../ClientGlobalContext.js.aspx" type="text/javascript" ></script>

    <script src="Scripts/ContosoScript.js" type="text/javascript"></script>
    <link href="Styles/ContosoStyles.css" rel="stylesheet" type="text/css" />
</head>

备注

建议您不要使用包含根 WebResources 文件夹的相对路径(如 /WebResources/ClientGlobalContext.js.aspx),因为在多租户环境中可能导致页面丢失组织上下文。

ClientGlobalContext.js.aspx 页将包含一些全局事件处理程序。 这些事件处理程序将取消 onselectstartcontextmenuondragstart 事件。

另请参阅

客户端编程引用
客户端上下文(客户端引用)
执行上下文(客户端引用)
脚本即时引用的表单
为 Microsoft Dynamics CRM 2015 窗体编写代码
使用 Xrm.Page 对象模型

© 2017 Microsoft。 保留所有权利。 版权