Firstly, let’s take a look at the form-level notification functions under the Xrm.Page.ui namespace. The setFormNotification function takes in three parameters: the message that you want to display, the level of the notification – ERROR, WARNING, INFO (this is the default value), and a uniqueId which is referenced when calling the clearNotification function.
Form-Level Notification Example
Let’s assume that we have an entity called “Event” and we want to display a notification on the form to indicate how much seating space is left for the event. Our business rule is:
1. If between 30% and 60% of seats are filled, display an information message stating “Minimum Capacity Reached”
2. If between 60% and 90% of seats are filled, display a warning message stating “Boy this Event is Popular!”
3. If greater than 90% of seats are filled, display an error message stating “Nearing Maximum Capacity”
Xrm.Page.ui.setFormNotification("Minimum Capacity Reached", "INFO", "capacityFormNotification");
Xrm.Page.ui.setFormNotification("Boy this Event is popular!", "WARNING", "capacityFormNotification");
Xrm.Page.ui.setFormNotification("Nearing Maximum Capacity", "ERROR", "capacityFormNotification");
If we wanted to clear the notification, we can simply call the clearFormNotification function and pass in our unique id. For example:
The functions for field-level notification exist under the Xrm.Page.ui.control namespace and are called setNotification and clearNotification. The setNotification function takes in one message parameter while the clearNotification takes in no parameters. CRM will know which notification to clear based on the attribute that the notification is attached to.
Field-Level Notification Example
Xrm.Page.getControl("ros_date").setNotification("Woah! That’s a bit late!");
To clear this notification, we can simple call Xrm.Page.getControl("ros_date").clearNotification();
Finally, this wouldn’t be a good post if I didn’t test the limits of the form-level notifications. I tried setting 100 unique notifications on the Event form but only the first four are displayed. The form threw the following error:
I can see this being a well-utilised feature in many CRM implementations. Take a look at this blog on Colour Indicators to see how this requirement can be met in Dynamics CRM 2011. Please note that this is done using unsupported methods.