Thursday, October 17, 2013

Client side notifications in CRM2013- Part 1

In CRM2011, there was no out of box functionality to show notifications on the entity forms. We have used alert function of JavaScript to pop up the message boxs. There was no way to show the error messages on the form except using web resources. Microsoft has introduced some new JavaScript methods to achieve this functionality in CRM2013.
In CRM2013,notifications can be displayed on form level and/or on field level. This blog will explain How to use notification next to specific control on the entity form.
We can use the following 2 methods to display and clear the notification next to field/control on the form
  1. setNotification- Xrm.Page.getControl(controlname).setNotification(message) :
            This method will display a message near the control to indicate that data is not valid. When this method is used on Microsoft Dynamics CRM for tablets a red "X" icon appears next to the control. Tapping on the icon will display the message.
     2.  clearNotification- Xrm.Page.getControl(controlname).clearNotification() :
            Remove a message already displayed for a control. We have to remove the notification to save the form.
Here is the JavaScript code I wrote to display the notification if the “No of Employees” entered on account form is less than 5.
function fieldNotification() 
    //get the control
    cont = Xrm.Page.getControl("numberofemployees");

    //check if the value is greater than 5
    if (cont.getAttribute().getValue()<=5)
        //set the notification
         cont.setNotification("The number of employees should be more than 5");
       //clear the notification

The above screen shot displays the notification next to “No of employees” control.


This method is only available for updated entities. Please check the CRM SDK for the list of updated entities.

1 comment:

  1. Reading your blogs - very helpful even for beginners like me. Thank you Amreek.
    Couple of questions:
    1. How can we add similar logic for multiple fields /controls on the same form.
    2. Where do we keep the above code /function - high level steps will be helpful
    Thank you again,