Tip #398: Careful with those .js libraries

After denting his table, Mehmet “Sputnik” Ozdemir finally decided to use his call-a-friend card. The problem? After attaching this trivial piece of script to the birthday field

function dateonchange() {
   Xrm.Utility.alertDialog(
       Xrm.Page.getAttribute("birthdate").getValue());
}

one would reasonably expect to select a date and see that selected value (+local time) popping up in a box. Instead, the returned value was null. Sometimes but not always. Internet Explorer was spitting dummy telling the world that getHours is a non-existent function. Things were gloomy, table-denting, I’d say.

Collective brain traced it down to the inclusion of the well-known date manipulation library date.js. That’s what you get for a) using 7 years-old library and b) messing around with the prototypes of the standard javascript objects.

If you really want nice and easy date/time manipulation library then get on with the program and download moment.js library and then add multi-language support to top it off.

But the main lesson is that when you decide to use <noun of your choice>.js library in your next CRM project, test it extensively, always treat it as a suspect and give preference to those libraries that do not use jQuery.js.

Leave a Reply

Your email address will not be published. Required fields are marked *