Hide Subgrid button based on BPF Field

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 depending on the customer's requirement for example, we may have a requirement to complete a specific stage or specific data field before creating a Quote, and let’s say because of this requirement, we want to hide the New Quote button if a 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 the New Quote button from the Quote Subgrid based on the below field, if it is completed, we will show the new button; otherwise, we will hide the new button.

Quote Subgrid

To implement the above requirement, we are going to use Custom Rule, where we can call our JavaScript method to return true or false to the hide/show button, so let’s first create a web resource and write below simple script below.

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 web resource, I am using two methods. The first one is to the check value of the field and return true/false based on the value of the field. The second function we need to call on the Quote tab on change to refresh the ribbon of the quote subgrid.

Now we will add Quote entity metadata only (we don’t need anything else) and open our solution in the Ribbon Workbench Tool. Once it is opened, we need to customize the button using the below steps.

Customize Command

Once we have done that, we need to go to the Enable Rule section and add a new Enable rule like the one below.

Enable Rule Section

After that, we need to attach a new enable rule to the new button, so to the command used for the new button and under the Enable Rules section, add the new rule that we created in the previous step.

Enable Rules

Now publish your changes, and when we have this field not selected, a new button will be hidden like this.

Button

Once we have this field selected, we should be able to see this button.

Summary

We can use the custom rule to hide/show the subgrid button based on the parent entity BPF fields.

Hope it will help someone !!

Keep learning and Keep Sharing !!


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.