Pages

Tuesday, February 5, 2013

Custom CRM 2011 Form Notifications for UR12

[UPDATE: 2013.04.12 I added some additional tricks to this code, at the bottom.]

Before Update Rollup 12, it was relatively simple to use the original “form alert” hack (seen here, here, here, and here) to produce custom, inline alerts and notices for the end user.  It’s a great feature of the form, and I wish I knew why using it is unsupported.

Alas, many realized that these customizations would be undone by Update Rollup 12, and indeed they have.  So, allow me to show you what appears to be the “Microsoft” way of accessing the new form notification system.  The added bonus is that this method requires no additional libraries or external references, and should be cross-browser.  (Disclaimer: the following information was not released or documented by Microsoft; I discovered it after a few hours of pouring over Developer Tools in IE10.)

The original hack could never have been cross-browser, because it relied on the “htc” behavior file which backed the original “crmNotifications” element.  Fortunately, these functions haven’t changed… just moved to a new home.  Here’s the old way (pre-UR12):

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

notificationsArea.AddNotification('noteId1', 1, 'namespace', 'Message.');

And here’s the new way (post-UR12):

var notificationsList = Sys.Application.findComponent('crmNotifications');

notificationsList.AddNotification('noteId1', 1, 'namespace', 'Message.');

Both examples do the same thing in their respective CRM 2011 revisions.  This customization remains as unsupported as it ever was; however there is relatively little danger in using it.

Here are some additional tricks you can use:

notificationList.SetNotifications();

That will reset the notifications array with an empty set.  Also, you can hide the notifications area by using:
notificationList.SetVisible(false);

12 comments:

  1. And he is back!!!

    Great post David! I got headache to find how to use this feature in UR12/Polaris.

    ReplyDelete
  2. Thanks David. Great Help.
    Thomas

    ReplyDelete
  3. Randomly stumbled upon your blog... now bookmarked.

    MS lack of 'supported' forms notification is mind blowing.... thanks for this

    ReplyDelete
  4. Hi David,

    I am also facing similar issues for crm lookup control used in one of the HTML webresource. I had used the crm lookup on html file by hacing HTML of CRM Lookup control added to an entity form, to make it work I also had to add some of lookup relevant JS files to custom HTML file. It stopped work Post UR 12 update, however it was working Pre-UR 12.

    Do you have idea about how I can make the lookup work for UR 12/polaris and for multibrowser as well.

    Thanks in advance.

    ReplyDelete
  5. Great stuff works brillantly and saved my a good amount of time.
    Thanks,
    Renato

    ReplyDelete
  6. I have tried to use your steps, but when I try to use "AddNotification", it says: TypeError: Cannot call method 'AddNotification' of null

    Any idea why I can't do this?

    ReplyDelete
  7. Davin,

    You should always check to see if an object is null before attempting to access any of its members; I don't include that code here because I basically just wanted to get down to brass tacks and show which calls were different.

    Depending on which version of CRM 2011 you're deploying to, you need to implement one or both of the methods; and even then, you're at the mercy of the form--it must provide the notifications behavior. So far, I have used it on a few out-of-box entities, and custom entities successfully. But I can't speak to all entities.

    The error you've mentioned sounds identical to the problem that sent me in search of a post-UR12 solution, which led to create the second code block. I imagine that in a pre-UR12 environment, the new code might also produce this error. Like I said, you'll want to implement one or both of the code blocks using some validation on the return of document.getElementId() or Sys.Application.findComponent(). You may also have to validate the "Sys" and "Sys.Application" objects in pre-UR12 environments.

    Also, keep in mind that if the form doesn't support the notifications behavior, that you'll be limited (basically, a "null" result from both aforementioned methods). I haven't found a form that has this limit, so I would expect that you could get something to work.

    ReplyDelete
  8. Ah I see. I am on post UR 12 On-Premise installation. I am also using the Case entity. I do have a part of the form (which I can see by examining the source code of the page. Based on the results I am assuming that it doesn't support the methods because the form doesn't support it. Ah man. I have a work around. I've created a ta above the "General" section and have it set to visible, but the section inside is set to invisible. I display errors by making it visible and changing the text inside the field. I've also styled it using basic Javascript, font, background color, font color, and font size. I just don't have the pretty icons =(

    Thanks for you input though Dave, makes more sense now!

    ReplyDelete
  9. The answer to this question may be obvious, but is there a way to CLEAR the notifications on a form?

    ReplyDelete
  10. You can use:

    notificationList.SetNotifications();

    That will reset the notifications array with an empty set. Also, you can hide notifications by using:

    notificationList.SetVisible(false);

    ReplyDelete

Unrelated comments to posts may be summarily disposed at the author's discretion.