CRM Crate

Understanding the getGlobalContext client API in Model Driven App / D365

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.

Understanding the getGlobalContext client API in Model Driven App / D365

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:

PropertyDescription
clientReturns information about the client.
organizationSettingsReturns information about the current organization settings.
userSettingsReturns 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 :

NameTypeRequiredDescription
settingStringYesName 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:

ValueClient
https://[org].crm.dynamics.commodel-driven apps (online)
http(s)://[server]/[org]model-driven apps (on-premises)
https://localhost:2525model-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 :

NameTypeRequiredDescription
successCallbackFunctionYesA function to call when the business app name is returned.
errorCallbackFunctionYesA 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:

NameTypeRequiredDescription
successCallbackFunctionYesA 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
errorCallbackFunctionYesA 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:

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

NameTypeRequiredDescription
webResourceNameStringYesName 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:

NameTypeRequiredDescription
sPathStringYesA local path to a resource.

JavaScript Snippet Syntax:

var globalContext = Xrm.Utility.getGlobalContext();
globalContext.prependOrgName(sPath);

Thus, we learned the usage of getGlobalContext client API in Model Driven App / D365

3 2 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.