Form And Fields Notification In Dynamics 365 - Part One

Dynamics 365 provides different ways to implement client side notifications. We can implement them in different levels. In this article, we are going to provide different methods which can be used to work with notifications.

setNotification

This method is used to work with individual controls over entity form. We can make use of this method to implement our client side data validation and display error notifications to the user. For example, let’s say we want to implement a validation into mobile number field of account entity and we want to make sure that user does not enter the text value in mobile field. This is just an example but it can be used in actual requirements similarly. So, let’s use setNotification method with mobile field, using the following code.

  1. Xrm.Page.getControl(arg).setNotification(message,uniqueId)  

 As we can see, it takes two parameters -

  • message The notification that we want to display to the user.
  • uniqueId The unique id associated to the notification.

So, to implement our validation, we can use the following method.

  1. function OnChange_telephone() { 
  2. var mobile=Xrm.Page.getAttribute("telephone1").getValue(); 
  3. if(isNaN(mobile)) 
  4. Xrm.Page.getControl("telephone1").setNotification("Please enter correct mobile number","101"
  5. }  

We can bind the above method on change of telephone1 field in account entity.

 

If user enters some text under telephone field, it will show the error notification like the following.

 

clearNotification

This method is used to clear the notification which is set using setNotification method, with the help of unique notification id. For example, if we want to remove the notification from an earlier example, it can be like the following.
  1. Xrm.Page.getControl("telephone1").clearNotification("101");  

setFormNotification

This method is used to set the notification at form level. This is very useful if we want display a consolidated notification, or want to remind the user about the current record, or want to display some error message at form level.

We can use the  following statement for form notification.
  1. Xrm.Page.ui.setFormNotification(message, level, uniqueId);  

Where message is the notification that we want to display to the user, and the level represents type of notification that we want to show, we can pass any of the following three parameters.

  • ERROR To display error notification to the user which will have a red cross sign.
  • WARNING To display warning to the user and it will show the system warning icon.
  • INFO To display the information to the user with system info icon.

Let's say, we have one flag (two option set fields) over the account entity which stores information about whether the customer submitted a verification document or not. If verification document is not submitted we want to display a reminder to the customer, so we can use code like the following,

  1. function setDocumentNotification() {  
  2.     var isdocumentsubmitted = Xrm.Page.getAttribute("new_isdocumentsubmitted").getValue();  
  3.     if (!isdocumentsubmitted) Xrm.Page.ui.setFormNotification("Please submit your verification documents""INFO""2001");  
  4. }  

We can call the above method on account entity form onload and when user opens it, it will display a notification based on the flag like the following.


clearFormNotification

This method is used to clear the notification at form level. We can pass unique id of the notification and clear it like following.

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

We can add the above code in our existing web resource. 

In the next article,  we will discuss some more notification methods. Stay tuned for the next article on Dynamics 365 notifications!!!


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.