{"id":4482,"date":"2023-08-31T07:52:28","date_gmt":"2023-08-31T07:52:28","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4482"},"modified":"2023-09-01T04:53:14","modified_gmt":"2023-09-01T04:53:14","slug":"hide-subgrid-button-based-on-bpf-field","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4482","title":{"rendered":"Hide Subgrid button based on BPF Field"},"content":{"rendered":"<p><strong>Requirement<\/strong><br \/>\nAs we know in Dynamics 365 CE, Business Process Flows (BPF) play a pivotal role in guiding users through predefined stages of business processes. These stages can vary from depending on the customer requirement for example we may have requirement to complete specific stage or specific data field before creating Quote and let&#8217;s say because of this requirement we want to hide New Quote button if specific field is not filled. In this post I am going to share steps to perform this.<\/p>\n<p><strong>Details<\/strong><br \/>\nLet&#8217;s say we want to hide New Quote button from the Quote Subgrid based on the below field, if it is completed we will show new button otherwise we will hide new button.<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4483 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF1-300x275.png\" alt=\"BPF1\" width=\"300\" height=\"275\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF1-300x275.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF1.png 441w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>To implement above requirement we are going to use Custom Rule, where we can call our java script method to return true or false to hide\/show button so let&#8217;s first create a web resource and write below simple script there:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar HIMBAP= window.Sdk || {};\r\n(function () {\r\n  this.HideQuoteNewButton = function (primaryControl) {\r\n            debugger;\r\n        var formContext = primaryControl;\r\n        if(formContext.getControl(&quot;header_process_presentfinalproposal&quot;)!=null &amp;&amp; \r\n        formContext.getControl(&quot;header_process_presentfinalproposal&quot;).getAttribute()!=null &amp;&amp; \r\n        formContext.getControl(&quot;header_process_presentfinalproposal&quot;).getAttribute().getValue()!=null)\r\n        {\r\n        return (formContext.getControl(&quot;header_process_presentfinalproposal&quot;).getAttribute().getValue() == true);\r\n        }\r\n      else\r\n       return false;\r\n      },\r\n      this.RefreshRibbonButtons=function(executionContext)\r\n      {\r\n          \r\n            var formContext = executionContext.getFormContext(); \r\n            var gridContext = formContext.getControl(&quot;quote&quot;); \/\/name of the subgrid\r\n         \r\n            if(gridContext!=null)\r\n                  gridContext.refreshRibbon();\r\n      }\r\n\r\n\r\n\r\n}).call(HIMBAP);\r\n\r\n<\/pre>\n<p>In the above webresource I am using two methods, first one is the check value of the field and return true\/false based on the value of the field. Second function we need to call on the Quote tab on change to refresh ribbon of the quote subgrid.<\/p>\n<p>Now we will add Quote entity metadata only (we don&#8217;t nee anything else) and open our solution in the Ribbon Workbench Tool. Once it is opened, we need to customize the button using below steps:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4484 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF2-300x144.png\" alt=\"BPF2\" width=\"300\" height=\"144\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF2-300x144.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF2-1024x490.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF2-624x299.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF2.png 1188w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Once we have done that we need to go to the Enable Rule section and need to add a new Enable rule like below:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4485 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF4-300x150.png\" alt=\"BPF4\" width=\"300\" height=\"150\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF4-300x150.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF4-624x312.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF4.png 908w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>After that we need to attached new enable rule to the new button, so to the to command used for the new button and under the Enable Rules section add the new rule which we created in previous step.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF5.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4486 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF5-300x115.png\" alt=\"BPF5\" width=\"300\" height=\"115\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF5-300x115.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF5-624x239.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF5.png 682w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now publish your changes and when we will have this field not selected, new button will be hidden like this:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF6.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4487 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF6-300x165.png\" alt=\"BPF6\" width=\"300\" height=\"165\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF6-300x165.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF6-624x343.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/08\/BPF6.png 982w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Once we have this field selected we should be able to see this button.<\/p>\n<p><strong>Summary<\/strong>:<br \/>\nWe can use custom rule to hide\/show subgrid button based on the parent entity BPF fields.<\/p>\n<p>Hope it will help someone !!<br \/>\n<strong>Keep learning and Keep Sharing !!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirement As we know in Dynamics 365 CE, Business Process Flows (BPF) play a pivotal role in guiding users through predefined stages of business processes. These stages can vary from depending on the customer requirement for example we may have requirement to complete specific stage or specific data field before creating Quote and let&#8217;s say because of this requirement we&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4482\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,402],"tags":[1041,1042,1044,1043],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4482"}],"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=4482"}],"version-history":[{"count":4,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4482\/revisions"}],"predecessor-version":[{"id":4491,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4482\/revisions\/4491"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}