Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Dynamics CRM Alert and Notification JavaScript Methods

Post Author: Joe D365 |

Before CRM 2013, if you wanted to alert a user on a form within the browser, the only method available was the standard JavaScript alert. This method would open an alert window over the record the user is viewing, which then must be acknowledged in order for the user to continue.

The code,

alert("This is a standard alert")

produces the pop up window as illustrated below.

Data

With CRM 2013, Microsoft introduced an additional alert method that is specific to CRM, Xrm.Page.ui.setFormNotification. This newer method allows you to specify three different types of alerts: error, information, and warning. Furthermore, instead of popping a window open over the current window, setFormNotification embeds the notification in the CRM page itself. These codes:

Xrm.Page.ui.setFormNotification("This is an INFORMATION notification.", "INFORMATION")

Xrm.Page.ui.setFormNotification("This is a WARNING notification. ", "WARNING")

Xrm.Page.ui.setFormNotification("This is an ERROR notification. ", "EROR")

produce the notifications in the screenshot below that are visible just under the Account record title.

Dynamics CRM Alert and Notification JavaScript Methods

The code

Xrm.Page.ui.clearFormNotification()

can be used to clear these notifications.

Additionally, you can call out specific fields with the setNotification method. The code

Xrm.Page.getControl("fax").setNotification("This is a notification about the Fax field")

produces the notification attached to the fax field on the Account record shown below.

Dynamics CRM Alert and Notification JavaScript Methods

With these different methods, you can now carefully choose how overt or subtle you would like to be in calling out important information on a record to users.

Want to stay up to date with our blog? Subscribe today!

Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

6 comments on “Dynamics CRM Alert and Notification JavaScript Methods”

  1. Good roundup but small correction. The 'information' level form notification should be INFO rather than INFORMATION. This produces a blue 'i ' icon rather than the icon-free notification shown

  2. Any idea how to add a conditional layer to this, so the alert would only display if a certain field on the contact form is set to Yes. I'm fine with the old js alert in the pop-up box, but just wondering if anyone can offer any help with how this script would look. Thanks!

  3. How to clear the notification if set on a specific field using the getControl method?

  4. I have multiple fields that I need to setnotification and i am using below code
    HandleCaseTimestamps = function (context) {
    var saveEvent = context.getEventArgs();
    var timeStampFields = ["ava_workaroundacceptedtime", "ava_workaroundrejectedtime", "ava_solutionavailabletime",
    "ava_solutionacceptedtime", "ava_solutionrejectedtime", "ava_emergencycallout", "ava_emergencyrestoredtime",
    "ava_systemoutagestarted", "ava_systemoutageended", "ava_1stoutagenotification"];
    var today = new Date();

    if (timeStampFields != null) {
    for (var i = 0; i today) {
    //alert("Please enter a date that is not in future");
    Xrm.Page.getControl(timeStampFields[i]).setNotification("Please enter a date that is not in future")//I am not sure if this way i can set for all fields.
    saveEvent.preventDefault();
    }
    }
    }
    }
    };

    I face issues here.
    Suppose I 4 fields in my form and a user enters future date. Through notification I am showing user the message above. Once I set the date to current date or before future date, the focus and error symbol still stays in the same field rather it should go the next field where he has entered another future date clearing the previous one.

PowerObjects Recommends