CRM 2015 SDK: How to recognize user’s form factor and client

When you’re working on multi-device projects in Dynamics CRM, sometimes you need to know the form factor that the user is currently using in order to execute or note some UI actions using Javascript. Dynamics CRM 2015 makes it easier and suggests using the context object with getFormFactor() method that returns an integer between 0 and 3.

Javascript Code: Xrm.Page.context.client.getFormFactor()

Return Value Form Factor
0 Unknown
1 Desktop (Warning that does not mean Computer, it can also be a desktop version used from a tablet navigator)
2 Tablet Application
3 Phone Application

Let’s apply this to a simple example, we will run an alert box containing the name of the form factor on form loading:

Javascript Code: function myTestFunction()

{

var formFactor = Xrm.Page.context.client.getFormFactor();

if(formFactor == ‘1’) { alert(“Desktop”);}
else if (formFactor == ‘2’) { alert (“Tablet App”); }
else if (formFactor ==’3′) { alert (“Phone App”); }
else { alert (“Unknown form factor”); }
}

 

To get which client the script is executing in, you can use:

 

Javascript Code: Xrm.Page.context.client.getClient()

The return value of this method is a String. These are the returned values:

Client Value
Browser Web
Outlook Outlook
Mobile Mobile

 

For more client-side context methods, you can visit https://msdn.microsoft.com/en-us/library/gg334511.aspx

 

 

 

 

.

2 thoughts on “CRM 2015 SDK: How to recognize user’s form factor and client

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s