Form and Fields Notification in Dynamics 365 Part 2

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. So 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 our following articles related to business rules:

Business rules enhancements in Dynamics 365
Business Rules Enhancement in MS CRM 2015
Apply Field Validations without writing Java Script in MS CRM 2013

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

addNotification
This method provide additional functionality to perform actions apart from just displaying notification compared to earlier notification methods. Using this method we can add notification to control as well as associate actions based on the notification. This methods use object with following attributes:
Message:- The message that we want to display to user.
NotificaitonLevel:- Which specify if we want to display error or recommendation. By default this is set to error.
uniqueId– unique id for notification.
Actions– This specify what action we want to perform, we can use following attributes for actions.
message: Description of the action that we want to display to 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 based on the industry selected by the user similar to our business rule example here. We can create a web resource and use following code:

function AddSICRecommendation() {
    var industry = Xrm.Page.getControl('industrycode');
    var industrycodevalue = Xrm.Page.getAttribute('industrycode').getValue();
    var siccode = Xrm.Page.data.entity.attributes.get('sic');
    if (industrycodevalue == 1 && siccode.getValue() != '8721') {
        var actionsCol = {
            message: 'Want to set SIC code for Industry?',
            actions: null
        };

        actionsCol.actions = [function() {
            siccode.setValue('8721');
            industry.clearNotification('2002');
        }];

        industry.addNotification({
            messages: ['Set SIC Code'],
            notificationLevel: 'RECOMMENDATION',
            uniqueId: '2002',
            actions: [actionsCol]
        });
    }

}

We need to bind this code on onload of account entity and onchange of industry field. Once we saved and published our changes, when user will select industry it will show an information icon like following:

setnotification4

And when user will move mouse over information icon, it will show following notification with action buttons:
setnotification5

And if user will click on Apply button it will set SIC code based on our JavaScript logic like following:
setnotification6

We hope these articles will help you to implement JavaScript notifications in Dynamics 365.

Stay tuned for more Dynamics 365 updates!!

One thought on “Form and Fields Notification in Dynamics 365 Part 2

  1. Pingback: Form and Fields Notification in Dynamics 365 Part 2 - Microsoft Dynamics CRM Community

Leave a Reply

Your email address will not be published. Required fields are marked *