Javascript functions of Xrm.Page.context

Javascript plays very crucial part in MS CRM projects. While writing down any javascript, we need to read the CRM context for few details like organization name, client url. Below javascript snippets gives details about each function of context.

1. Xrm.Page.context.client.getClient();

this code snippet will returns the results about client details. whether Web, Outlook or Mobile.

2. Xrm.Page.context.client.getClientState();

this code will return the client state. possible return values are; For web client  it will returns always "Online".  For outlook and mobile it can be either "Online" or "Offline"

3. Xrm.Page.context.client.getFormFactor();

this getFormFactor() will returns integer value which will indicate what kind of devices user is using.

0  - Unknown
1 - Desktop
2 - Tablet
3 - Phone

4. Xrm.Page.context.getClientUrl();

this method will returns the base url of current application.

5. Xrm.Page.context.getCurrentTheme();

this method will returns the current Microsoft Office Outlook theme using by the user.this function mostly userful for client type Outlook. for web application this function will returns "default".

6. Xrm.Page.context.getIsAutoSaveEnabled();

this function will return boolean variable based on Auto Save function is enabled or not.

7. Xrm.Page.context.getOrgLcid();

this will returns the base language of the organization. For english its values is 1033.

8. Xrm.Page.context.getOrgUniqueName();

this function will returns the current organization name.

9. Xrm.Page.context.getQueryStringParameters();

this function will returns an object which contains all the query string parameters of the form contains.

10. Xrm.Page.context.getTimeZoneOffsetMinutes();

this function will returns the minutes difference between local time to UTC time.

11. Xrm.Page.context.getUserId();

this function will returns the guid of an user who logged into the application.

12. Xrm.Page.context.getUserLcid();

this function will returns the base language user has been selected.

13. Xrm.Page.context.getUserName();

this function will returns the name of the user who logged into the application.

14. Xrm.Page.context.getUserRoles();

this function will returns the array of roles assigned to the current user.




You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM










Enable Tracing in MS CRM 2015 & Below versions

Enabling MS CRM tracing till 2015 new feature is through Registry keys only. But MS CRM 2015 gives this feature as UI. It is really useful for reading the errors we are getting in Plugins and workflow.

Below are the steps to enable to tacing in MS CRM 2015.

1. MS CRM 2015 --- Settings --->Administration ---> System Settings ---> Customization Tab--->
set Enable logging to plug-in trace log as "Exception" as shown in below screen.

























Thats it, now we can read our exceptions in CRM application itself under below path.

Settings---> Plug-in Trace Log


Trace log contains information related to Configuration, TypeName, MessageName, PrimaryEntity, OperationType, Depth, StpeId, CorrelationId, Mode, ExecutionTime, Duration, Excetion Message & Detail, Full Stack.

For CRM 2013 and below versions, we can enable the tracing through registry keys on CRM server.

1. Windows->Run-> Type "regedit" (You should have administrator role to open this registry)
In Registry Editory:
2. HKEY-LOCAL_MACHINE-->SOFTWARE --->Microsoft ---> MS CRM
3. In Right side panel , you can find two DWords called TraceEnabled and TraceRefresh
4. Right click on TraceEnabled DWord ---> Modify ----> Set ValueData to "1" to enable tracing or set ValueData to "0" to disable the Tracing.
5. After you set the value for TraceEnabled, Righ click on TraceRefresh DWord ---> Modify ---> Give any numeric number (Preferably two digit number). TraceEnable will not be reflect until you refresh the tracing through TraceRefresh Dword


If you don't find those DWords in RegistryEditor in given path. then add those DWords
1. Right click on MSCRM ---> New---> DWord(32-bit) value ---> Give name as "TraceEnabled" set Value data as 0.
similary create a DWord for TraceRefresh with data value as any two digit number ex.22

Trace files will be generated in  Trace folder which is in where MS CRM software get installed.



You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM


Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...