this will break your phone app scripts
When writing JavaScript for CRM forms I like to encase all form functions within a namespace library in a very similar fashion to what Microsoft suggest here. It ends up looking like follows.
//If the LSD namespace object isn’t defined, create it. if (typeof (LSD) == "undefined") { LSD = {}; } // Create Namespace container for functions in this library; LSD.Appointment= { onLoad: function(){ this.retrieveLocation(); }, retrieveLocation: function(){ console.log("retrieving contact address"); } };
Recently I rewrote some form scripts for appointment to add additional functionality, replaced web service calls using the 2011 Endpoint with the WebAPI and also took the opportunity to create a namespaced library. I tested the changes in Dev and UAT before finally deploying to live.
Today I received a phonecall from one of the sales guys who informed me I had broken the phone app.
Oops, I had forgot to test the script changes on the app. Had I have done so I would have discovered that you cannot use the this keyword to call functions within the namespace when using the phoneapp, you must use the full name as shown below.
//If the LSD namespace object isn’t defined, create it. if (typeof (LSD) == "undefined") { LSD = {}; } // Create Namespace container for functions in this library; LSD.Appointment= { onLoad: function(){ LSD.Appointment.retrieveLocation(); }, retrieveLocation: function(){ console.log("retrieving contact address"); } };
So there are a few lessons there:
- Never use this if you intend on using the CRM phone app
- Always, always test your scripts in the phone app before deploying to live.
This was originally posted here.
*This post is locked for comments