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’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.
Details
Let’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.
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’s first create a web resource and write below simple script there:
var HIMBAP= window.Sdk || {}; (function () { this.HideQuoteNewButton = function (primaryControl) { debugger; var formContext = primaryControl; if(formContext.getControl("header_process_presentfinalproposal")!=null && formContext.getControl("header_process_presentfinalproposal").getAttribute()!=null && formContext.getControl("header_process_presentfinalproposal").getAttribute().getValue()!=null) { return (formContext.getControl("header_process_presentfinalproposal").getAttribute().getValue() == true); } else return false; }, this.RefreshRibbonButtons=function(executionContext) { var formContext = executionContext.getFormContext(); var gridContext = formContext.getControl("quote"); //name of the subgrid if(gridContext!=null) gridContext.refreshRibbon(); } }).call(HIMBAP);
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.
Now we will add Quote entity metadata only (we don’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:
Once we have done that we need to go to the Enable Rule section and need to add a new Enable rule like below:
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.
Now publish your changes and when we will have this field not selected, new button will be hidden like this:
Once we have this field selected we should be able to see this button.
Summary:
We can use custom rule to hide/show subgrid button based on the parent entity BPF fields.
Hope it will help someone !!
Keep learning and Keep Sharing !!