Dynamics CRM 2011 · Javascript

Show Info / Warning / Error message in CRM 2011 Notification Area with Javascript

Most of the time when I need to display a message to user from within CRM form, I rely on Javascript alert() function. As a warning media, it is intrusive, annoying and demands user’s attention and action; in other words, it works. But wouldn’t it be nice if we can show the message through CRM built in notification area like the message that appears when you try to send an email to a contact who doesn’t have a valid email address? Well, here is how.

To show message in CRM 2011 notification area:

var notificationsArea = document.getElementById('crmNotifications');

//severity: critical = 1, warning = 2, info = 3
notificationsArea.AddNotification("<message unique id>", <severity>, "<source>", "<message>");

//to clear notification messages
notificationsArea.SetNotifications(null, null);

Some code that will make life somewhat easier

//severity: critical = 1, warning = 2, info = 3
function ShowNotification(messageId, message, severity) {
    var notificationsArea = document.getElementById('crmNotifications');
    if (notificationsArea == null) {
        alert('notification div not found');
        return;
    }

    notificationsArea.AddNotification(messageId, severity, 'source', message);
}

function ClearNotification() {
    var notificationsArea = document.getElementById('crmNotifications');

    if (notificationsArea == null) {
        alert('notification div not found');
        return;
    }

    notificationsArea.SetNotifications(null, null);
}

You can add multiple messages to the notification area, and they will be shown sorted by severity.

Removing specific message can probably be done although with some degree of complexity using GetNotifications() and SetNotifications() functions. I haven’t had the need to though.

Cheers – Sy

Advertisements

15 thoughts on “Show Info / Warning / Error message in CRM 2011 Notification Area with Javascript

  1. Hi Sy,
    Good post. i got 2 more things with the alert to be done,
    – need the alerts to be side by side (left to right) rather than top to bottom.
    – need the alerts to be shown for the navigation pane items also in the form. (since my nav entites will count according to the related entities in it)

    Any help would be greatly appreciated.
    Thanks
    Bob

    1. Hi Bob,

      Thanks for the comments.

      How will the format be for side by side comments? I imagine you’ll quickly run out of space.
      I think you might be able to either modify the stylesheet for the notification element, but not quite sure whether this is supported.

      Can you elaborate abit more about the alerts to be shown for the navigation pane items? Are you talking about the record list page?

      Sy

      1. Sy,
        what i was referring was that i wrote a code to show the count on the navigation pane items(ex: under related in the form–> connection, activities. if it has any activities in it then it show like this activities(1), connections(3)…so i have to show alert on main form to the user when it has count on load… if you understand and know any solution …lt would be great…

        thanks
        Bob

      2. Hi Bob,

        Apologies for the late reply. I haven’t done anything like that before. But looks like the customization will be unsupported. Are your clients open to a different approach? Say displaying this on the form instead?

        Sy

  2. Sy,
    Can tell me how that works. if that answers the requirement May be i can use it. Can you brief it to me.
    Bob

    1. Hi Bob,

      What I was thinking is either a HTML/Silverlight web resource showing the number of connections/activities on the record form itself. Either that or you can just use the notification pane to show query result onload with the format you’ve mentioned “activities(1), connections(3)”.

      Sy

  3. Sy,
    do you have any info on doing the HTML/Silverlight web resource for showing the connections alert.
    thanks.
    Gary

  4. Gary,
    Unfortunately I don’t have any sample code since I have not done it before. But the idea is using html/silverlight web resource that queries CRM for the connections/activities and display the result.
    Sy

  5. Hi Sy,
    Can I pass crm announcements on the Home screen(Dashboard) instead of the “Get Outlook for CRM” notification in the Yellow strip
    Thanks,
    Chintan

    1. Hi Chintan,

      What do you mean? CRM has announcement function that you can use, however it works differently with notification.

      Cheers,
      Sy

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