Show ribbon button only on selected sub-grid of the same entity | Ribbon Workbench | Dynamics 365 CRM

In some scenarios, you might need to show only specific buttons on a sub-grid of an entity but this sub-grid is being used at multiple places and hence, all the buttons appear in each of them and not filtered based on the purpose of the sub-grid at a specific location.

Let’s look at a scenario to understand this better!

Default Scenario

By default, you’ll see all the buttons added to sub-grid in all instances of the sub-grid for the same entity.

Expected Outcome

Let’s look at this scenario to understand better –

  1. Account has a child entity Subscriptions. Now, under Account, there are 2 sub-grids for the same child entity –
    Active Subscriptions & Past Subscriptions

  2. Now, in order to have different buttons on these like
    Active Subscriptions should show End Subscription.
    Past Subscriptions should show Reactivate.

  3. To achieve this, we’ll be using Custom Rule in Enable Enable Rules in Ribbon Workbench. Let’s review how we can achieve this.

Separate Buttons on different Sub-grid based on View

Here, the approach is to have separate buttons on the sub-grids based on the “Name of the View”. We’ll achieve this using JavaScript, let’s review how –

  1. In your Ribbon Workbench, by default you have both the buttons added.
    So first, we’ll add the condition to show the buttons only on record selection –


    The way this is implemented is that you can attach an Enable Rule to the Command of the ribbon button.


    And the actual Rule is as below

  2. Now, the way the buttons should be separated are based on the name of the view itself.

  3. In order to observe what buttons should be shown on the above view, we will go the Custom Rule approach in Ribbon Workbench for the Enable Rule which is tied to the Command itself (which in turn, is attached to the actual button).
    For Inactive View, the below Enable Rule will be applied.

    And for Active Subscription grid, we’ll use the below Enable Rule which is meant for Active Subscriptions view.

  4. And, in one of the Custom Rules, you’ll see that we are calling a JS function which will check whether to return True or False based on what View the button is being run on.
    In the below Enable Rule, we are adding a Custom Rule which is calling a JS function and we are passing the current SelectedControl parameter (in this case, it’s the view itself!)

  5. And the function looks like below –
    It’ll return if the current View is the one intended.
    In the below example, we are reading what the selectedControl is – And if it matches the one we want to match to i.e. the intended Enable Rule, the True or False value are set based on the same.


    And that’s how you can have each Command in RibbonWorkbench work off of different JS functions which identifies the current View that the Command’s button is present on.

    And once this works, you’ll see the correct buttons show up on either of the views as required.


Code Samples

Here are the code samples which you can copy and modify for your own experiment –

oSubscriptionFormCustomization = {

    forActiveSubscriptionView: function (selectedControl) {
        "use strict";
        debugger;
        var currentGridName = selectedControl._controlName;
       
      
        var excludedPayRun = "ActiveSubscriptions";
        if (currentGridName == excludedPayRun) {
         return true;
        } 
    else { return false; }
    },
    
    forInactiveSubscriptionView: function (selectedControl) {
        "use strict";
        debugger;
        var currentGridName = selectedControl._controlName;
      
      
        var excludedPayRun = "InactiveSubscriptions";
        if (currentGridName == excludedPayRun) {
         return true;
        } 
    else { return false; }
    }
};      

Hope this was useful!

Here are some Power Automate posts you want to check out –

  1. Blocking Attachment Extensions in Dynamics 365 CRM
  2. Upgrade Dataverse for Teams Environment to Dataverse Environment
  3. Showing Sandbox or Non Production Apps in Power App mobile app
  4. Create a Power Apps Per User Plan Trial | Dataverse environment
  5. Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
  6. Co-presence in Power Automate | Multiple users working on a Flow
  7. Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
  8. Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
  9. Call a Flow from Canvas Power App and get back response | Power Platform\
  10. FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
  11. Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
  12. Asynchronous HTTP Response from a Flow | Power Automate
  13. Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
  14. Converting JSON to XML and XML to JSON in a Flow | Power Automate

Thank you!

Advertisement

One thought on “Show ribbon button only on selected sub-grid of the same entity | Ribbon Workbench | Dynamics 365 CRM

  1. Just one precision : the selectedControl has a getName() function which is documented and supported whereas the property _controlName is not documented nor supported

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.