Client-Side Context Reference
Your code will need to operate within a context where a number of variables are not known at design time. The context object provides methods to retrieve information specific to an organization, a user, or parameters passed to a page.
The context object is available within forms by referencing Xrm.Page.context.
For web resources executed outside of a form, use the GetGlobalContext Function to retrieve a context object.
The following table lists all the methods of the context object.
| Method | Description |
|---|---|
| A deprecated method that returns the encoded SOAP header necessary to use Microsoft Dynamics CRM 4.0 web service calls using Microsoft JScript. | |
| Returns a string representing the current Microsoft Office Outlook theme chosen by the user. | |
| Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the base language for the organization. | |
| Returns the unique text value of the organizations name. | |
| Returns an array of key value pairs representing the query string arguments that were passed to the page. | |
| Returns the base server URL. The format of this URL can change depending on whether the user is connected to on-premises Microsoft Dynamics CRM 2011, Microsoft Dynamics CRM Online, or working offline with Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access. | |
| Returns GUID value of the SystemUser.Id value for the current user. | |
| Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language. | |
| Returns an array of strings that represent the GUID values of each of the security roles that the user is associated with. This method does not return GUID values that represent the team security roles that the user may belong to. For more information about security roles, see How Role-Based Security Can Be Used to Control Access to Entities in Microsoft Dynamics CRM. | |
| Returns a Boolean value indicating if the user is using the Microsoft Dynamics CRM for Microsoft Office Outlook client. | |
| Returns a Boolean value indicating whether the user is connected to the Microsoft Dynamics CRM server while using the Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access client. When this function returns false, the user is working offline without a connection to the server. They are interacting with an instance of Microsoft Dynamics CRM running on their local computer. | |
| Prepends the organization name to the specified path. |
getAuthenticationHeader
Note |
|---|
| This method is deprecated. The global getAuthenticationHeader is still available for backwards compatibility for Microsoft Dynamics CRM 4.0 scripts that are upgraded. Scripts using the SOAP endpoint for web resources or the REST endpoint for web resources do not require this function for authentication. |
Returns the encoded SOAP header necessary to used for Microsoft Dynamics CRM 4.0 web service calls using JScript. For more information about using the Microsoft Dynamics CRM 4.0 web services see the Accessing Microsoft Dynamics CRM Web Services topic in the Microsoft Dynamics CRM 4.0 SDK.
- Return Value
- Type: String
getCurrentTheme
Returns a string representing the current Microsoft Office Outlook theme chosen by the user.
- Return Value
- Type: String
Use this information to select an appropriate theme for your HTML and Silverlight web resources when viewed in the Microsoft Dynamics CRM for Microsoft Office Outlook client. The following table lists the values that may be returned from this method.
Value Theme default
Microsoft Dynamics CRM Web application
Office12Blue
Microsoft Dynamics CRM for Outlook 2007 or 2010 Blue Theme
Office14Silver
Microsoft Dynamics CRM for Outlook 2007 or 2010 Silver or Black Theme
getOrgLcid
Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the base language for the organization.
- Return Value
- Type: Number Example: 1033 indicates the English language. Valid locale ID values can be found at Locale ID (LCID) Chart.
getOrgUniqueName
Returns the unique text value of the organization’s name.
- Return Value
- Type: String Example: This corresponds to the organization name value
getQueryStringParameters
Returns a dictionary object of key value pairs representing the query string arguments that were passed to the page.
- Return Value
- Type: String
getServerUrl
Returns the base server URL. The format of this URL can change depending on whether the user is connected to on-premises Microsoft Dynamics CRM 2011, Microsoft Dynamics CRM Online, or working offline with Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access.
- Return Value
- Type: String Example: While the user is connected to the network using on-premises Microsoft Dynamics CRM 2011, the value is:
When the user is working offline with Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access the organization name is not included and the value is:
"http://localhost:2525"
The following example show how to trim a trailing forward slash character if it exists.
Note Microsoft Dynamics CRM Online returns a string that includes a trailing forward slash character. If two consecutive forward slash characters are used in a URL to open a form, the ribbon will not display. To prevent this, always trim the trailing forward slash character so that your code will work the same for Microsoft Dynamics CRM Online and on-premises Microsoft Dynamics CRM 2011. if (serverUrl.match(/\/$/)) { serverUrl = serverUrl.substring(0, serverUrl.length - 1); }
Note The URL returned is the standard URL used to access the application. If you access the server locally using http://localhost or use an IP address instead of the actual name of the server, this will not be reflected in the value returned by this function. This means that if you are making web service calls or accessing web resources, Internet Explorer will apply security settings that apply to requests that cross domains. To avoid this, always connect to Microsoft Dynamics CRM using the standard URL.
getUserId
Returns GUID value of the SystemUser.Id value for the current user.
- Return Value
- Type: String Example:
getUserLcid
Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.
- Return Value
- Type: Number Example: 1041 indicates the Japanese language.Valid locale ID values can be found at Locale ID (LCID) Chart.
getUserRoles
Returns an array of strings that represent the GUID values of each of the security roles that the user is associated with. This method does not return GUID values that represent team security roles that the user may belong to.
For more information about security roles, see How Role-Based Security Can Be Used to Control Access to Entities in Microsoft Dynamics CRM.
- Return Value
- Type: Array Example: This user has only one security role associated with their user account. The JSON representation of this array with a single value is:
isOutlookClient
Returns a Boolean value indicating if the user is using the Microsoft Dynamics CRM for Microsoft Office Outlook client.
- Return Value
- Type: Boolean
isOutlookOnline
Returns a Boolean value that indicates whether the user is connected to the Microsoft Dynamics CRM server while using the Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access client. When this function returns false, the user is working offline without a connection to the server. They are interacting with an instance of Microsoft Dynamics CRM running on their local computer.
- Return Value
- Type: Boolean
prependOrgName
Send comments about this topic to Microsoft.
© 2012 Microsoft Corporation. All rights reserved.