We will learn and understand the getGlobalContext client API in Model Driven App / D365. Before we start, make sure to subscribe to CRM Crate so that you can stay up to date in the field of Power Apps.
What is getGlobalContext client API ?
The getGlobalContext client API reference is used to get the global context of an application. The method provides access to the global context without going through the form context. The getGlobalContext client API contains an equivalent of all the methods which were available in the Xrm.Page.context.
To access the global context information in a standalone HTML Web resource, you should include a reference to ClientGlobalContext.js.aspx in the web resource, and then use the GetGlobalContext function. Click on the given link to understand more about the ClientGlobalContext.js.aspx reference- https://docs.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/getglobalcontext-clientglobalcontext.js.aspx
Below are the properties of getGlobalContext client API .
Use the following properties of global context to return information about the client, organization settings, or user settings:
Property | Description |
---|---|
client | Returns information about the client. |
organizationSettings | Returns information about the current organization settings. |
userSettings | Returns information about the current user settings. |
Exploring methods of Global Context (getGlobalContext)
Below are the details of methods present in the scope of global context client API.
1. getAdvancedConfigSetting
getAdvancedConfigSetting (Client API reference)
This method returns information about the advanced configuration settings for the organization.
Parameters :
Name | Type | Required | Description |
---|---|---|---|
setting | String | Yes | Name of the configuration setting. Only the following two configuration settings are supported: “MaxChildIncidentNumber” and “MaxIncidentMergeNumber” |
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getAdvancedConfigSetting(setting);
2. getClientUrl
getClientUrl (Client API reference)
This method returns the base URL that was used to access the application.
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getClientUrl();
Return Value:
Value | Client |
---|---|
https://[org].crm.dynamics.com | model-driven apps (online) |
http(s)://[server]/[org] | model-driven apps (on-premises) |
https://localhost:2525 | model-driven apps for Outlook with Offline Access when offline |
3. getCurrentAppName
getCurrentAppName (Client API reference)
This method returns the name of the current business app in model-driven apps.
Parameters :
Name | Type | Required | Description |
---|---|---|---|
successCallback | Function | Yes | A function to call when the business app name is returned. |
errorCallback | Function | Yes | A function to call when the operation fails. |
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getCurrentAppName().then(successCallback, errorCallback);
4. getCurrentAppProperties
getCurrentAppProperties (Client API reference)
This method returns the properties of the current business app in model-driven apps.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
successCallback | Function | Yes | A function to call when the business app property information is returned. An object with the following attributes (app properties) is passed to the function : – appId – displayName – uniqueName – url – webResourceId – webResourceName – welcomePageId – welcomePageName |
errorCallback | Function | Yes | A function to call when the operation fails. |
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getCurrentAppProperties().then(successCallback, errorCallback);
5. getCurrentAppUrl
getCurrentAppUrl (Client API reference)
This method returns the URL of the current business app in model-driven apps.
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getCurrentAppUrl();
Return Value:
Value | Client |
---|---|
https://[org].crm.dynamics.com/main.aspx?appid=[GUID] | model-driven apps (online) |
https://[server]/[org]/main.aspx?appid=[GUID] | model-driven apps (on-premises) |
6. getVersion
getVersion (Client API reference)
This method returns the version number of the model-driven apps instance.
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getVersion();
7. getWebResourceUrl
getWebResourceUrl (Client API reference)
This method returns the relative URL with the caching token for the specified web resource.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
webResourceName | String | Yes | Name of the web resource. |
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.getWebResourceUrl(webResourceName);
8. isOnPremises
isOnPremises (Client API reference)
This method returns a boolean value indicating if the model-driven apps instance is hosted on-premises or online.
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.isOnPremises();
9. prependOrgName
prependOrgName (Client API reference)
Prefixes the current organization’s unique name to a string, typically a URL path.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
sPath | String | Yes | A local path to a resource. |
JavaScript Snippet Syntax:
var globalContext = Xrm.Utility.getGlobalContext();
globalContext.prependOrgName(sPath);