A Good Common JavaScript Library for Microsoft Dynamics CRM 2011

In the XRM project I currently work on for a leading global fast-food chain, I use the following common library to help me easily query records in CRM with JavaScript (i.e. client-side):

http://www.bizforward.cws-international.com/2011/03/09/useful-javascript-functions-and-methods-for-crm-2011-cws-crm-utils-js-library

One problem I have discovered with this library is that it redefines the native Date class, which in turns prevents you from using the out-of-the-box JavaScript Date functions. To overcome this issue, I simply commented out the prototype and function definitions for Date.

//// Add days to a certain Date
//Date.prototype.addDays = function (days) {
//    this.setDate(this.getDate() + days);
//}

//// Formats the date into a certain format
//Date.prototype.Format = function (format) {
//    var d = this;
//    var f = "";

//    try {
//        f = f + format.replace(/dd|mm|yyyy|MM|hh|ss|ms|APM|\s|\/|\-|,|\./ig,
//    function match() {
//        switch (arguments[0]) {
//            case "dd":
//                var dd = d.getDate();
//                return (dd < 10) ? "0" + dd : dd;
//            case "mm":
//                var mm = d.getMonth() + 1;
//                return (mm < 10) ? "0" + mm : mm;
//            case "yyyy": return d.getFullYear();
//            case "hh":
//                var hh = d.getHours();
//                return (hh < 10) ? "0" + hh : hh;
//            case "MM":
//                var MM = d.getMinutes();
//                return (MM < 10) ? "0" + MM : MM;
//            case "ss":
//                var ss = d.getSeconds();
//                return (ss < 10) ? "0" + ss : ss;
//            case "ms": return d.getMilliseconds();
//            case "APM":
//                var apm = d.getHours();
//                return (apm < 12) ? "AM" : "PM";
//            default: return arguments[0];
//        }
//    });
//    }
//    catch (err) {
//    }

//    return f;
//}

//// Formats the date to CRM format
//Date.prototype.toCRMFormat = function () {
//    var d = this;
//    var f = d.Format("yyyy-mm-ddThh:MM:ss+" + (-d.getTimezoneOffset() / 60) + ":00");

//    return f;
//}
Advertisements

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 )

Google+ photo

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

Connecting to %s