Tuesday, August 23, 2011

CRM 2011: Notification area

Hello Gang,

I was working on a solution for a client and wanted to put some information into the notification area.  As usual this is not supported by Microsoft.  I wanted to add fields in the notification area that needed to be populated to move a picklist field on the lead object forward.

We need to create some JavaScript (Web Resource) and load it into the form we're working against:


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');
        return;
    }
    /*
    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");
}

This gives us the following:


The JS code the defines the notification behavior is located in \Microsoft Dynamics CRM\CRMWeb\_static\_controls\notifications.  

You should be able to use the .setNotifications method to clear out a single notification if needed.  I've just never had this need.  If you do drop me a note and I'll figure it out.

Happy slinging!

---------

Update!

With the release of R12 the above JS has some trouble working.  I took the solution from a comment against this post.
function DC_Notification() {
    var attributes = Xrm.Page.data.entity.attributes;
    
    var notificationsArea = $find('crmNotifications');
    /*clear out notification area*/
    notificationsArea.SetNotifications(null, null);

    if (notificationsArea == null)
    {
        alert('div not found');
        return;
    }
    /*
    The integer is the notification type
    1 = Error
    2 = Warning
    3 = Info
    notificationsArea.AddNotification("&lt;;unique value&gt;;", 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");
}