There is a new client API  feature introduced in CRM 2013 – Setting Form and Field level notifications through Jscript.

Let’s have a look at how to set the form notification on the Account form.

We will be using the new Xrm.page.ui.setFormNotitication() method to achieve this.

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

Parameters

message | Type: String. The text of the message.

level | Type: String. 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 | Type: String. A unique identifier for the message used with clearFormNotification to remove the notification.

Sample Method which calls this method – registered on the OnSave() event of Account form

function AlertOnAccountForm() {
 Xrm.Page.ui.setFormNotification('Sample Error Notification message for Demo ', 'ERROR', '1');
 Xrm.Page.ui.setFormNotification('Sample information Notification message for Demo ', 'INFORMATION', '2');
 Xrm.Page.ui.setFormNotification('Sample Warning Notification message for Demo ', 'WARNING', '3'); }

And the form UI will be like this:

FormNotofication_screen

By default, the notifications would be sorted in the below order of notification type

  1. Information
  2. Error
  3. Warning

In order to clear the notification, Xrm.page.ui.clearFormNotification() method can be used by passing the uniqueid as parameter.

function ClearAccountFormNotification() {
Xrm.Page.ui.clearFormNotification('1');
}


And the notification with id ‘1’ [Error added] will be removed from the form

FormNotofication_screen_clearError

©Dynamics CRM Guru Blog

Advertisements