Notifications in MSCRM using Javascript

It’s a new JavaScript feature in CRM 2013.

setFormNotification

 To Display Form Level Notifications we can use this method. The height of the Notification area is limited. So, every new notification will be displayed on the top. Users can scroll down for the older notifications.

Syntax:

Xrm.Page.ui.setFormNotification(message, level, uniqueId);
Parameter Name Type Description
message String The text of the message
level String 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 String A unique identifier for the message used with clearFormNotification to remove the notification.

Example: Display all Form Level Notifications on OnLoad of Case entity.

Solution:Copy & Paste the below functions in a JScript Webresource and add the function callFormNotification on Onload

function callFormNotification() {
 setFormNotification("Error Notification", "ERROR", "1");
 setFormNotification("Warning Notification", "WARNING", "2");
 setFormNotification("Information Notification", "INFO", "3");
}
function setFormNotification(msg, msgType, uniqueId) {
 Xrm.Page.ui.setFormNotification(msg, msgType, uniqueId);
}

Output:

Notification Output

clearFormNotification

To remove Form Level Notifications we can use this method.

Syntax:

Xrm.Page.ui.clearFormNotification(uniqueId)
Parameter Name Type Description
uniqueId String A unique identifier for the message used with setFormNotification to set the notification.

Example: Remove error Notification in the above example.

Solution: Copy & Paste the below function in a JScript Webresource and add the function removeErrorNotification on Onload

function removeErrorNotification() {
 clearFormNotification("1");
}
function clearFormNotification(uniqueId) {
 Xrm.Page.ui.clearFormNotification(uniqueId);
}

Output:

clearNotificationOutput

Field Level Notifications:

setNotificaion: To Set Notification at field Level.
Sytax:

Xrm.Page.getControl(fieldSchemaName).setNotification(message);
Parameter Name Type Description
fieldSchemaName String Provide field Schema Name
message String Provide message to display

clearNotification: To Remove Notificaion at field Level

Sytax:

Xrm.Page.getControl(fieldSchemaName).clearNotification();

Please provide your valuable comments on this article.

Advertisements