Here is my new blog post and here I will cover some of the points
that one should keep in mind while writing JavaScript code that is required to
work in the mobile clients. I will refer to Dynamics CRM 2015 and the latest
mobile application for Dynamics CRM (not the express version) throughout this
post.
From MSDN and TechNet, I present some links that one should
definitely read before thinking that most of the functionality for Dynamics CRM
for mobile will come out of the box with no changes in your existing scripts.
1. Writing and debugging scripts for the mobile client: https://msdn.microsoft.com/en-in/library/dn481572.aspx
2. Customize CRM for phones and tablets: https://technet.microsoft.com/en-us/library/dn531159.aspx
Also, from experience here are some additional points that you
should keep in your mind while developing your scripts when you want them to be
Dynamics CRM mobile client ready:
1. Defensive coding: You may already know that there is an option
to enable/disable fields, sections and tabs specifically for the mobile client.
In case these very fields, sections or tabs have a dependency in any of the
scripts that have been written then you will be getting pretty bad alerts
splashing out. To avoid it the best way is to do defensive coding: check
whether the attribute, control, section or tab is not null before using any of
their properties or methods.
Validate whether a control exists or not:
var controlObj = Xrm.Page.getControl(“control_name”);
if(controlObj){
// Logic goes here that uses the properties and methods in controlObj
}
Validate whether an attribute exists or not:
var attributeObj = Xrm.Page.getAttribute(“attribute_name”);
if(attributeObj){
// Logic goes here that uses the properties and methods in
attributeObj
}
Validate whether a tab exists or not:
var tabObj = Xrm.Page.ui.tabs.get(“tab_name”);
if(tabObj){
// Logic goes here that uses the
properties and methods in tabObj like setVisible, etc.
}
Validate whether a section exists or not:
var tabObj = Xrm.Page.ui.tabs.get(“tab_name”);
if(tabObj){
var sectionObj = tabObj.sections.get(“section_name”);
if(sectionObj){
//Logic goes here that uses the
properties and methods in sectionObj like setVisible, etc.
}
}
As a side note: We do not need to explicitly validate for
null and undefined for the sectionObj, tabObj etc. and can just do the check
using if(sectionObj),
etc. as in JavaScript all values with a “actual” value is true whereas all
values without an “actual” value like null, empty string or undefined are
false. Please refer here.
2.
Other than the ways to debug mentioned in the links above, I have also found
that tracing the Microsoft Dynamics CRM app for tablets also helps to diagnose
hard to detect issues like corrupted deployments, etc. The procedure to set up
the tracing is a bit involved and are different for the mobile phone and the
tablet client.
The
detailed steps are mentioned in this TechNet article:
Look
in particular the Enable tracing for CRM for phonesfor Windows Phone and Enable tracing for CRM for tablets sections for enabling tracing in
the Windows Phone client and tablet clients respectively.
Edit: Here is an useful link that highlights some of the limitations of the CRM for tablets app in terms of fields, sections and tabs: http://crmtipoftheday.com/2014/09/29/increase-the-limits-of-crm-for-tablets/
Hope
this post helps you in making sure that your JavaScript customizations work
seamlessly in the mobile client for Dynamics CRM.
In
case of any questions or any feedbacks for improvement, feel free to reach out
to me.
Cheers
and have a good day!
No comments:
Post a Comment