{"id":2634,"date":"2017-01-04T17:47:42","date_gmt":"2017-01-04T17:47:42","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=2634"},"modified":"2018-10-02T23:32:31","modified_gmt":"2018-10-02T23:32:31","slug":"form-and-fields-notification-in-dynamics-365-part-1","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=2634","title":{"rendered":"Form and Fields Notification in Dynamics 365 Part 1"},"content":{"rendered":"<p>Dynamics 365 provides different ways to implement client side notifications, we can implement them in different level. In this article we are going to provide different methods which can be used to work with notifications.<\/p>\n<p><strong>setNotification<\/strong><br \/>\nThis method is used to work with individual control over entity form. We can make use of this method to implement our client side data validation and display error notification to user for example let\u2019s say we want to implement a validation into mobile number field of account entity and we want to make sure user should not enter text value in mobile field. This is just an example but it can be used in actual requirement similarly. So let\u2019s use setNotification method with mobile field using following code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nXrm.Page.getControl(arg).setNotification(message,uniqueId)\r\n<\/pre>\n<p>As we can see it takes two parameter:<br \/>\n<strong>message<\/strong>:- The notification that we want to display to user.<br \/>\n<strong>uniqueId<\/strong>:- The unique id associated to notification.<\/p>\n<p>So to implement our validation, we can use following method:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction OnChange_telephone()\r\n{\r\nvar mobile=Xrm.Page.getAttribute(&quot;telephone1&quot;).getValue();\r\nif(isNaN(mobile))\r\nXrm.Page.getControl(&quot;telephone1&quot;).setNotification(&quot;Please enter correct mobile number&quot;,&quot;101&quot;)\r\n}\r\n<\/pre>\n<p>We can bind above method onchange of telephone1 field in account entity:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification1.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2642 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification1-300x85.png\" alt=\"setnotification1\" width=\"300\" height=\"85\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification1-300x85.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification1-624x177.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification1.png 677w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>If user will enter some text under telephone field it will show the error notification like following:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification2.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2643 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification2-300x177.png\" alt=\"setnotification2\" width=\"300\" height=\"177\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification2-300x177.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification2.png 384w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>clearNotification<\/strong><br \/>\nThis method is used to clear notification which is set using setNotification method with the help of unique notification id. For example if we want to remove notification from earlier example it can be like following:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nXrm.Page.getControl(&quot;telephone1&quot;).clearNotification(&quot;101&quot;);\r\n<\/pre>\n<p><strong>setFormNotification<\/strong><\/p>\n<p>This method is used to set notification at form level. This is very useful if we want display a consolidated notification or may be want to remind user something about current record or want to display some error message at form level, we can use this option.<\/p>\n<p>We can use following statement for form notification:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nXrm.Page.ui.setFormNotification(message, level, uniqueId);\r\n<\/pre>\n<p>Where message is the notification that we want to display to user and level represent type of notification that we want to show. We can pass any of the following three parameters:<\/p>\n<p><strong>ERROR<\/strong>:- To display error notification to user which will have a Red Cross sign.<br \/>\n<strong>WARNING<\/strong>:\u2013 To display warning to user and it will show system warning icon.<br \/>\n<strong>INFO<\/strong>:\u2013 To display information to user with system info icon.<\/p>\n<p>Let say we have one flag (two option set field) over account entity which stores information if customer submitted verification document or not. If verification document is not submitted we want to display reminder to customer, so we can use code like following:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction setDocumentNotification() {\r\n    var isdocumentsubmitted = Xrm.Page.getAttribute(&quot;new_isdocumentsubmitted&quot;).getValue();\r\n    if (!isdocumentsubmitted)\r\n        Xrm.Page.ui.setFormNotification(&quot;Please submit your verification documents&quot;, &quot;INFO&quot;, &quot;2001&quot;);\r\n}\r\n<\/pre>\n<p>We can call above method on account entity form onload and when user will open it will display notification based on the flag like following:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification3.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2646 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification3-300x229.png\" alt=\"setnotification3\" width=\"300\" height=\"229\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification3-300x229.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2017\/01\/setnotification3.png 429w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>clearFormNotification<\/strong><br \/>\nThis method is used to clear notification at form level. We can pass <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/developer\/clientapi\/reference\/formcontext-ui\/clearformnotification\">unique id <\/a>of the notification and clear it like following:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nXrm.Page.ui.clearFormNotification(uniqueId);\r\n<\/pre>\n<p>We can add above code in our existing web resource. In next article we will discuss some more notification methods.<\/p>\n<p>Stay tuned for next article on Dynamics 365 notifications !!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dynamics 365 provides different ways to implement client side notifications, we can implement them in different level. In this article we are going to provide different methods which can be used to work with notifications. setNotification This method is used to work with individual control over entity form. We can make use of this method to implement our client side&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=2634\">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,402,6,8],"tags":[429,424,426,425,412],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2634"}],"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=2634"}],"version-history":[{"count":14,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2634\/revisions"}],"predecessor-version":[{"id":3367,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2634\/revisions\/3367"}],"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=2634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}