Zdieľať cez


Client-side context (client-side reference)

 

Applies To: Dynamics CRM 2015

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.

Context properties and methods

  • client
    Provides access to the getClient, getClientState and getFormFactor methods you can use to determine which client is being used, whether the client is connected to the server, and what kind of device is being used.

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

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

  • getIsAutoSaveEnabled
    Returns whether Autosave is enabled for the organization.

  • getOrgLcid
    Returns the language code identifier (LCID) value that represents the base language for the organization.

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

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

  • getTimeZoneOffsetMinutes
    Returns the difference between the local time and Coordinated Universal Time (UTC).

    This method was introduced with Microsoft Dynamics CRM Online 2015 Update 1.

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

  • getUserLcid
    Returns the LCID value that represents the provisioned language that the user selected as their preferred language.

  • getUserName
    Returns the name of the current user.

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

  • prependOrgName
    Prepends the organization name to the specified path.

  • Removed methods
    Removed methods are either obsolete or replaced with other methods. You should make sure these methods are not used in your scripts.

    The getAuthenticationHeader and getServerUrl methods were deprecated with Microsoft Dynamics CRM 2011 and are no longer present in Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update.

    The isOutlookClient and isOutlookOnline methods were deprecated with Microsoft Dynamics CRM 2013 and are no longer present in Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update.

client

Microsoft Dynamics CRM 2013 and Microsoft Dynamics CRM Online added the client object which contains the getClient and getClientState methods to get information about the client.

Microsoft Dynamics CRM Online 2015 Update 1 added the getFormFactor method.

getClient

Returns a value to indicate which client the script is executing in.

context.client.getClient()

Use this instead of the removed isOutlookClient method.

  • Return Value
    Type: String

    The values returned are:

    Client

    Value

    Browser

    Web

    Outlook

    Outlook

    Mobile

    Mobile

getClientState

Use this instead of the removed isOutlookOnline method.

Returns a value to indicate the state of the client.

context.client.getClientState()
  • Return Value
    Type: String

    The possible values returned are:

    Client

    Values returned

    Web, Outlook, Mobile

    Online

    Outlook, Mobile

    Offline

getFormFactor

Use this method to get information about the kind of device the user is using.

context.client.getFormFactor()
  • Return Value
    Type: Number

    The possible values returned are:

    Value

    Form factor

    0

    Unknown

    1

    Desktop

    2

    Tablet

    3

    Phone

  • Remarks
    This method was introduced with Microsoft Dynamics CRM Online 2015 Update 1

getClientUrl

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

context.getClientUrl()

Use this instead of the removed getServerUrl method.

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

https://localhost:2525

  • Return Value
    Type: String

getCurrentTheme

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

Note

This function doesn’t work with Microsoft Dynamics CRM for tablets.

context.getCurrentTheme()
  • Return Value
    Type: String

Use this information to select an appropriate theme for your HTML and Silverlight web resources when viewed in Microsoft Dynamics CRM for Outlook. The following table lists the values that may be returned from this method.

Note

Forms don’t adapt to changes in the Microsoft Office theme, so the only case where you might want to adapt to the Microsoft Office themes is when you display a page in the navigation using an HTML web resource. Even in this scenario, visual differences may be difficult to detect.

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

getIsAutoSaveEnabled

This method is new for Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update

Returns whether Autosave is enabled for the organization.

context.getIsAutoSaveEnabled()
  • Return Value
    Type: Boolean

    Note

    This function returns the value set at the time the page is opened. When testing code using this value, you must refresh the page after changing the value in order to get the new value.

    More information: TechNet: Manage auto-save.

getOrgLcid

Returns the LCID value that represents 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
    

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"
    

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

getTimeZoneOffsetMinutes

Returns the difference between the local time and Coordinated Universal Time (UTC).

Note

This method was introduced with Microsoft Dynamics CRM Online 2015 Update 1.

context.getTimeZoneOffsetMinutes()
  • Return Value
    Type: Number

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

getUserLcid

Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that 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
    

getUserName

Returns the name of the current user.

context.getUserName()
  • Return Value
    Type: String

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.

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

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
    

Removed methods

Removed methods are either obsolete or replaced with other methods. You should make sure these methods aren’t used in your scripts.

The following methods were deprecated with earlier versions of Microsoft Dynamics CRM and are no longer present in the current version:

See Also

GetGlobalContext function and ClientGlobalContext.js.aspx (client-side reference)
Form scripting quick reference
Write code for Microsoft Dynamics CRM forms
Use the Xrm.Page object model
Client-side programming reference

© 2016 Microsoft. All rights reserved. Copyright