Form And Fields Notification In Dynamics 365 - Part Two

In our earlier article, we started discussing about notification in Dynamics 365. In this article, we are going to discuss some new notification method, which was introduced in Dynamics 365. Thus, let’s discuss this new method. This method provides similar functionality like recommendation action in business rule. If you are new to business rule, check the articles given below related to business rules.

Back to our topic, so let’s discuss the new method introduced in Dynamics 365.

  • addNotification

    This method provides an additional functionality to perform the actions apart from just displaying notification compared to earlier notification methods. Using this method, we can add the notification to control, as well as associate actions based on the notification. This methods uses an object with the attributes given below.

    • Message
      The message that we want to display to the user.
    • NotificaitonLevel
      We want to specify, if we want to display an error or recommendation. By default, this is set to an error.
    • uniqueId
      unique id for the notification.
    • Actions
      This specifies what action we want to perform, i.e. we can use the attributes given below for the actions.
    • message
      Description of the action, which we want to display to the user.
    • actions
      The corresponding actions for the message.

Now, we know about this method. Let’s implement a simple scenario, where we want to recommend SIC code, which is based on the industry selected by the user and is similar to our business rule example here. We can create a Web resource and use the code given below.

  1. function AddSICRecommendation() {  
  2.     var industry = Xrm.Page.getControl('industrycode');  
  3.     var industrycodevalue = Xrm.Page.getAttribute('industrycode').getValue();  
  4.     var siccode ='sic');  
  5.     if (industrycodevalue == 1 && siccode.getValue() != '8721') {  
  6.         var actionsCol = {  
  7.             message: 'Want to set SIC code for Industry?',  
  8.             actions: null  
  9.         };  
  10.         actionsCol.actions = [function() {  
  11.             siccode.setValue('8721');  
  12.             industry.clearNotification('2002');  
  13.         }];  
  14.         industry.addNotification({  
  15.             messages: ['Set SIC Code'],  
  16.             notificationLevel: 'RECOMMENDATION',  
  17.             uniqueId: '2002',  
  18.             actions: [actionsCol]  
  19.         });  
  20.     }   

We need to bind this code on onload of an account entity and onchange of the industry field. Once we save and publish our changes, the user will select an industry and it will show an information icon, as shown below.

When the user will move mouse over information icon, it will show the notification given below with action buttons.

If the user will click on Apply button, it will set SIC code, which is based on our JavaScript logic, as shown below.

I hope, this article will help you to implement JavaScript notifications in Dynamics 365.

Stay tuned for more Dynamics 365 updates.