{"id":2651,"date":"2017-01-06T08:34:17","date_gmt":"2017-01-06T08:34:17","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=2651"},"modified":"2017-01-06T08:40:12","modified_gmt":"2017-01-06T08:40:12","slug":"form-and-fields-notification-in-dynamics-365-part-2","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=2651","title":{"rendered":"Form and Fields Notification in Dynamics 365 Part 2"},"content":{"rendered":"<p>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\u2019s 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:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/?p=2541\">Business rules enhancements in Dynamics 365<\/a><br \/>\n<a href=\"https:\/\/himbap.com\/blog\/?p=1421\">Business Rules Enhancement in MS CRM 2015<\/a><br \/>\n<a href=\"https:\/\/himbap.com\/blog\/?p=1201\">Apply Field Validations without writing Java Script in MS CRM 2013<\/a><\/p>\n<p>Back to our topic, so let\u2019s discuss the new method introduced in Dynamics 365.<\/p>\n<p><strong>addNotification<\/strong><br \/>\nThis 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:<br \/>\n<strong>Message<\/strong>:- The message that we want to display to user.<br \/>\n<strong>NotificaitonLevel<\/strong>:- Which specify if we want to display error or recommendation. By default this is set to error.<br \/>\n<strong>uniqueId<\/strong>&#8211; unique id for notification.<br \/>\n<strong>Actions<\/strong>&#8211; This specify what action we want to perform, we can use following attributes for actions.<br \/>\n<strong>message<\/strong>: Description of the action that we want to display to user.<br \/>\n<strong>actions<\/strong>: The corresponding actions for the message.<\/p>\n<p>Now we know about this method, let\u2019s 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:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction AddSICRecommendation() {\r\n    var industry = Xrm.Page.getControl('industrycode');\r\n    var industrycodevalue = Xrm.Page.getAttribute('industrycode').getValue();\r\n    var siccode = Xrm.Page.data.entity.attributes.get('sic');\r\n    if (industrycodevalue == 1 &amp;&amp; siccode.getValue() != '8721') {\r\n        var actionsCol = {\r\n            message: 'Want to set SIC code for Industry?',\r\n            actions: null\r\n        };\r\n\r\n        actionsCol.actions = [function() {\r\n            siccode.setValue('8721');\r\n            industry.clearNotification('2002');\r\n        }];\r\n\r\n        industry.addNotification({\r\n            messages: ['Set SIC Code'],\r\n            notificationLevel: 'RECOMMENDATION',\r\n            uniqueId: '2002',\r\n            actions: [actionsCol]\r\n        });\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>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:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification4.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2654 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification4-300x159.png\" alt=\"setnotification4\" width=\"300\" height=\"159\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification4-300x159.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification4.png 318w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>And when user will move mouse over information icon, it will show following notification with action buttons:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification5.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2655 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification5-300x177.png\" alt=\"setnotification5\" width=\"300\" height=\"177\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification5-300x177.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification5.png 353w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>And if user will click on Apply button it will set SIC code based on our JavaScript logic like following:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification6.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2656 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification6-300x129.png\" alt=\"setnotification6\" width=\"300\" height=\"129\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification6-300x129.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification6.png 318w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>We hope these articles will help you to implement JavaScript notifications in Dynamics 365.<\/p>\n<p>Stay tuned for more Dynamics 365 updates!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019s 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&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=2651\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":2661,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[428,429,427,412],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2651"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2651"}],"version-history":[{"count":5,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2651\/revisions"}],"predecessor-version":[{"id":2659,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2651\/revisions\/2659"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/2661"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}