How To Show Form Level Notification On Any Microsoft Dynamics CRM Page

Using JavaScript for development is always bliss and today, Microsoft dynamics CRM developers will get new experience by learning the steps for showing Form level notification on any CRM page using JavaScript.  To learn how to make it happen, you can read this post further without any break!

Previously, we had explained how to show Field level error message on Form using Business Rule in CRM. So, today we will explain how to show Form level notification using java script on any CRM page.

There are three types of form level messages available.

  1. Error notification
  2. Warning notification
  3. Information notification

The method is used to display these three notification is same as below.

“setFormNotification”

Now, I created a web resource in CRM with following function, and set the call of this function on form save event of CRM page.

 function SaveForm()   
 {  
               var today = new Date();  
 Xrm.Page.ui.setFormNotification('Error! Birth Date is required', 'ERROR');  
 Xrm.Page.ui.setFormNotification('Warning! Birth Date is greater than Parent’s Marriage date', 'WARNING');  
 Xrm.Page.ui.setFormNotification('Information: Form will save after valid data', 'INFORMATION');  
 }  

This will display messages on form as below.



The second time when you click save button the same messages display twice in alphabetical order but user only show three messages on screen, because it is default behavior of CRM UI and setFormNotification() function of CRM SDK. The user has to scroll down to show other remaining messages.

To overwrite this default functionality, we can set unique ID to each notification and overwrite so now user will show only three messages on screen same as below.

 function SaveForm()   
 {  
               var today = new Date();  
 Xrm.Page.ui.setFormNotification('Error! Birth Date is required', 'ERROR', '1');  
 Xrm.Page.ui.setFormNotification('Warning! Birth Date is greater than Parent’s Marriage date', 'WARNING', '2');  
 Xrm.Page.ui.setFormNotification('Information: Form will save after valid data', 'INFORMATION', '3');  
 }  

We can clear all using clearFormNotification() or individual notifications using clearFormNotification() with unique notification ID.

Xrm.Page.ui.clearFormNotification();
Xrm.Page.ui.clearFormNotification('1');

After reading above example, we hope you will be now able to show form level notification on any Microsoft dynamics CRM page using java script. You can share your experience with us. For general queries related to CRM development, please connect with our professionals. You can simply comment in below section and our experts in Microsoft dynamics CRM developers will reply soon.