Sunday, November 27, 2016

Enhancements to Client side Notifications in Dynamics 365

Microsoft introduced client side notifications in CRM2013. Dynamics 365 has introduced enhancements to this functionality.
A new method addNotification has been added to to the client side API. This method can:
  1. Display a error or recommendation notification. In the earlier version the only option available was error notifications.
  2. It also allows you to specify and execute actions based on the notification. The new method not only display the notification, it also display 2 buttons:
    • “Apply” to execute the action
    • “Dismiss” to close the notification

Code

The following sample code will display recommendation notification if there are numbers in the “name” of the account. If the user clicks on “Apply” button, it will remove the numbers from the name and clear the notification. If the user clicks on “Dismiss” button, the notification will be closed.
 function addNotification() {  
   //get the name control  
   var myControl = Xrm.Page.getControl('name');  
   //get the name attribute  
   var accountName = Xrm.Page.data.entity.attributes.get('name');  
   //get the value name attribute  
   var accountNameValue = accountName.getValue();  
   //if the account name is null then return  
   if (accountName.getValue() == null) {  
     return;  
   }  
   //regular expression to find numbers  
   var r = /\d+/;  
   var s = accountNameValue.match(r);  
   //if match the display the message  
   if (s != null) {  
     var actionCollection = {  
       message: 'Remove the numbers from the name?',  
       actions: null  
     };  
     actionCollection.actions = [function () {  
       //remove the numbers  
       accountName.setValue(accountNameValue.replace(/[0-9]/g, ''));  
       myControl.clearNotification('my_unique_id');  
     }];  
     myControl.addNotification({  
       messages: ['Number/s in the account name'],  
       notificationLevel: 'RECOMMENDATION',  
       uniqueId: 'my_unique_id',  
       actions: [actionCollection]  
     });  
   }  
 }  

Results

2016-11-25_22-36-28

When the user clicks “Apply”, the system removes the number 7 from the name.
2016-11-25_22-36-56

This functionality will be very useful in number of scenarios, for e.g. validating a field and recommending a value, moving the focus to specific tab or field, validating the field value on the parent entity, and opening the parent form to update the fields etc..

1 comment:

  1. Great... I can think of 101 use to this new feature

    ReplyDelete