Tuesday, April 24, 2012

Using JQuery and Json in Ribbon button’s function handler(Include JS files in Ribbon Button Script)

  • In one of my CRM 2011 requirement, I had to update a record using ribbon button placed on CRM grid.
  • I had written an update script which calls OData service using Json & JQuery. (link)
  • But when I execute the function, I got “$ undefined” exception.
  • I wondered since I already had “Json.js” & “JQuery.js” web resources added to my entity.
  • After digging deeper, I came to know that, “JQuery.js” web resource is not getting loaded when my ribbon button’s function handler fired.
Fix :-
  • I fixed the problem by loading “JQuery.js” web resource dynamically, before I call my update method.
  • Below is the script to load the web resource’s

 var JScriptWebResourceUrl = “../WebResources/new_JQuery”;
var xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
xmlHttp.open(“GET”, JScriptWebResourceUrl, false);

Saturday, April 21, 2012

CRM 2011 Add notifications to entity form

CRM 2011: Notification area

function DC_Notification() {
    var attributes = Xrm.Page.data.entity.attributes;
    var notificationsArea = document.getElementById('crmNotifications');
    /*clear out notification area*/
    notificationsArea.SetNotifications(null, null);

    if (notificationsArea == null)
        alert('div not found');
    The integer is the notification type
    1 = Error
    2 = Warning
    3 = Info
    notificationsArea.AddNotification("<;unique value>;", 3, "","Your text here");
    /*Create some notifications*/
    notificationsArea.AddNotification("1", 1, "1","Test 1");
    notificationsArea.AddNotification("2", 2, "2","Test 2");
    notificationsArea.AddNotification("3", 3, "3","Test 3");