web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Luke Sartain Dynamics / this will break your phone ...

this will break your phone app scripts

Luke Sartain Profile Picture Luke Sartain 1,266

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.

lsd_phoneapp_error

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:

  1. Never use this if you intend on using the CRM phone app
  2. Always, always test your scripts in the phone app before deploying to live.

This was originally posted here.

Comments

*This post is locked for comments