Udostępnij za pośrednictwem


GetGlobalContext function and ClientGlobalContext.js.aspx (client-side reference)

 

Applies To: Dynamics CRM 2015

Use the GetGlobalContext function when programming with web resources to gain access to context information. To get the GetGlobalContext function in your HTML web resource, include a reference to ClientGlobalContext.js.aspx.

GetGlobalContext function

The GetGlobalContext function returns the same context object found in the Xrm.Page.context.

When you need context information outside a form, include a reference to the ClientGlobalContext.js.aspx page in an HTML web resource.

The following example shows a function designed to return a context object when used in either a form script or a script used with an HTML web resource.

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

You can use the GetGlobalContext function when you include a reference to the ClientGlobalContext.js.aspx page located at the root of the web resources directory.

Note

If you are not using backslash characters in HTML web resource names to simulate a folder structure, you can include this script in your page using this script element: <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>

If you are using backslash characters in HTML web resource names to simulate a directory structure, you must reflect this in your script element. The following example is for an HTML web resource named ‘sdk_/Contoso.htm’ and a JScript web resource named ‘sdk_/Scripts/ContosoScript.js’ with a CSS web resource named ‘sdk_/Styles/ContosoStyles.css’.

<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>

Note

Using a relative path including the root WebResources folder, for example, /WebResources/ClientGlobalContext.js.aspx, is not recommended because it can cause the page to lose organization context in a multi-tenant environment.

The ClientGlobalContext.js.aspx page will include some global event handlers. These event handlers will cancel the onselectstart, contextmenu, and ondragstart events.

See Also

Client-side programming reference
Client-side context (client-side reference)
Execution context (client-side reference)
Form scripting quick reference
Write code for Microsoft Dynamics CRM forms
Use the Xrm.Page object model

© 2016 Microsoft. All rights reserved. Copyright