Client-Side Context Reference

[Applies to: Microsoft Dynamics CRM 2011]

Your code will need to operate in 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 in forms by referencing Xrm.Page.context.

For web resources executed outside of a form, use the GetGlobalContext Function to retrieve a context object.

Important

If your organization has been updated to Microsoft Dynamics CRM Online Fall ’13, please use the latest version of the SDK. Download the updated SDK package for Microsoft Dynamics CRM 2013 and CRM Online Fall ‘13.

Methods

The following table lists all the methods of the context object.

Method Description

getAuthenticationHeader

Deprecated. Returns the encoded SOAP header necessary to use Microsoft Dynamics CRM 4.0 web service calls using Microsoft JScript.

getClientUrl

Returns the base URL that was used to access the application.

getCurrentTheme

Returns a string that represents the current Microsoft Office Outlook theme chosen by the user.

getOrgLcid

Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the base language for the organization.

getOrgUniqueName

Returns the unique text value of the organizations name.

getQueryStringParameters

Returns an array of key value pairs representing the query string arguments that were passed to the page.

getServerUrl

Deprecated. Use getClientUrl instead. 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.

getUserId

Returns GUID value of the SystemUser.Id value for the current user.

getUserLcid

Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.

getUserRoles

Returns an array of strings that represent the GUID values of each of the security roles that the user is associated with or any teams that the user is associated with.

For more information about security roles, see How Role-Based Security Can Be Used to Control Access to Entities in Microsoft Dynamics CRM.

isOutlookClient

Returns a Boolean value indicating if the user is using the Microsoft Dynamics CRM for Microsoft Office Outlook client.

isOutlookOnline

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.

prependOrgName

Prepends the organization name to the specified path.

getAuthenticationHeader

Note

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

Methods

getClientUrl

Returns the base URL that was used to access the application.

This method is new in Microsoft Dynamics CRM 2011 Update Rollup 12 and the Microsoft Dynamics CRM December 2012 Service Update.

The values returned will resemble those listed in the following table.

Client Value

Microsoft Dynamics CRM (on-premises)

http(s)://server/org

Microsoft Dynamics CRM Online

https://org.crm.dynamics.com

Microsoft Dynamics CRM for Outlook with Offline Access when offline

http://localhost:2525

  • Return Value
    Type: String

Methods

getCurrentTheme

Returns a string representing the current Microsoft Office Outlook theme chosen by the user.

context.getCurrentTheme()
  • 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

Methods

getOrgLcid

Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the base language for the organization.

context.getOrgLcid()
  • Return Value
    Type: Number

    Example: 1033 indicates the English language. Valid locale ID values can be found at Locale ID (LCID) Chart.

    1033
    

Methods

getOrgUniqueName

Returns the unique text value of the organization’s name.

context.getOrgUniqueName()
  • Return Value
    Type: String

    Example: This corresponds to the organization name value

    "adventureworkscycle"
    

Methods

getQueryStringParameters

Returns a dictionary object of key value pairs that represent the query string arguments that were passed to the page.

context.getQueryStringParameters()
  • Return Value
    Type: String

Methods

getServerUrl

Note

Deprecated. Use getClientUrl instead. This method is deprecated as of Microsoft Dynamics CRM 2011 Update Rollup 12 and the Microsoft Dynamics CRM December 2012 Service Update.

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.

context.getServerUrl()
  • Return Value
    Type: String

    Example: While the user is connected to the network using on-premises Microsoft Dynamics CRM 2011, the value is:

    "http://[server name]/adventureworkscycle"
    

    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"
    

    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.

    The following example show how to trim a trailing forward slash character if it exists.

    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, the browser will apply security settings that apply to requests that cross domains. To avoid this, always connect to Microsoft Dynamics CRM using the getClientUrl method..

Methods

getUserId

Returns the GUID of the SystemUser.Id value for the current user.

context.getUserId()
  • Return Value
    Type: String

    Example:

    "{B05EC7CE-5D51-DF11-97E0-00155DB232D0}"
    

Methods

getUserLcid

Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.

context.getUserLcid()
  • Return Value
    Type: Number

    Example: 1041 indicates the Japanese language. Valid locale ID values can be found at Locale ID (LCID) Chart.

    1041
    

Methods

getUserRoles

Returns an array of strings that represent the GUID values of each of the security roles that the user is associated with and any teams that the user is associated with.

For more information about security roles, see How Role-Based Security Can Be Used to Control Access to Entities in Microsoft Dynamics CRM.

context.getUserRoles()
  • 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:

    ["cf4cc7ce-5d51-df11-97e0-00155db232d0"]
    

Methods

isOutlookClient

Returns a Boolean value indicating if the user is using Microsoft Dynamics CRM for Microsoft Office Outlook.

context.isOutlookClient()
  • Return Value
    Type: Boolean

Methods

isOutlookOnline

Returns a Boolean value that indicates whether the user is connected to the Microsoft Dynamics CRM server while using Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access. When this function returns false, the user is working offline without a connection to the server.

context.isOutlookOnline()
  • Return Value
    Type: Boolean

Methods

prependOrgName

Prepends the organization name to the specified path.

context.prependOrgName(sPath)
  • Arguments
    Type: String
A local path to a resource.
  • Return Value
    Type: String

    The value returned follows this pattern:

    "/"+ OrgName + sPath
    

Methods

See Also

Reference

Xrm.Page.context
GetGlobalContext Function

Concepts

Form Scripting Quick Reference
Write Code for Microsoft Dynamics CRM Forms
Use the Xrm.Page Object Model

Other Resources

Client-Side Programming Reference

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.