Tags

, , , , , ,

Hello Everyone,

Setting up the {Info, Warning, Error] notifications on the forms is a generic requirement for most of the time which are based on multiple scenarios (eg. on case page load to notify the agent any particular details about the customer). I use the below jScript again and again in my deployment so pinning it down below. The detailed are there in the MS article and docs.

 

setFormNotification:

Xrm.Page.ui.setFormNotification(message, level, uniqueId);

Where the 3 parameters are

message
TypeString. The text of the message.

level
TypeString. The level of the message.

The level defines how the message will be displayed.

  • ERROR : Notification will use the system error icon.
  • WARNING : Notification will use the system warning icon.
  • INFO : Notification will use the system info icon.
uniqueId
TypeString. A unique identifier for the message used with clearFormNotification to remove the notification.

 

clearFormNotification:

The Next script would be to clear those notification based on the uniqueId assigned to the notification above.

Xrm.Page.ui.clearFormNotification(uniqueId)

 

setTimeout:

And now the best part; flashing the formNotifications only for a couple of seconds and clear them automatically. This can be done via Timeout function:

setTimeout( function () { Xrm.Page.ui.clearFormNotification(id); }, time );

 

My overall sample code below:

var message = “The Contract is about to expiry, kindly consult customer to renew.”;
var type = “WARNING”;  //INFO, WARNING, ERROR
var id = “101”;  //Notification Id
var time = 5000;  //Display time in milliseconds

//Display the notification
Xrm.Page.ui.setFormNotification(message, type, id);

//Wait the designated time and then remove the notification
setTimeout( function () {Xrm.Page.ui.clearFormNotification(id);}, time );

 

I would keep this as a sticky note, thanks to Jason Lattimer for his blog post; it still works on the D365 forms.

🙂