{"id":4804,"date":"2026-10-13T15:14:04","date_gmt":"2026-10-13T15:14:04","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4804"},"modified":"2026-10-13T15:14:04","modified_gmt":"2026-10-13T15:14:04","slug":"hide-a-subgrid-button-based-on-parent-record-state","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4804","title":{"rendered":"Hide a Subgrid Button Based on Parent Record State"},"content":{"rendered":"\n<p>Introduction<\/p>\n\n\n\n<p>In Model driven apps, we sometimes need to show or hide a button on a subgrid based on the status of the parent record.<\/p>\n\n\n\n<p>For example, we have an <strong>Account<\/strong> entity and a related <strong>Contact <\/strong>entity. Users can add contract lines from a subgrid on the Contract form.<\/p>\n\n\n\n<p>Our requirement is simple:<\/p>\n\n\n\n<ul>\n<li>When the Account is active, users should be able to add contact.<\/li>\n\n\n\n<li>When the Account is inactive, users should not be able to add contact.<\/li>\n<\/ul>\n\n\n\n<p>We can achieve this by writing a custom JavaScript function and adding a custom rule in Ribbon Workbench. However, I found a simpler solution that can work for certain scenarios: using the built-in Mscrm.EntityFormIsEnabled rule.<\/p>\n\n\n\n<p><strong>Details<\/strong><\/p>\n\n\n\n<p>Mscrm.EntityFormIsEnabled is a built-in rule used in the classic Dynamics CRM ribbon command system.<\/p>\n\n\n\n<p>It checks whether the <strong>current entity form<\/strong> is enabled. For example, when a record is inactive or its form is disabled, this rule can prevent certain buttons from being enabled and that&#8217;s what we need.<\/p>\n\n\n\n<p><strong>How to implement the solution<\/strong><\/p>\n\n\n\n<p>Let&#8217;s see how we can use this rule to meet our requirement.<\/p>\n\n\n\n<p><strong>Step 1: Open Ribbon Workbench<\/strong><\/p>\n\n\n\n<p>Open your solution in Ribbon Workbench and select the child entity. In our example, this is the <strong>Contact <\/strong>entity.<\/p>\n\n\n\n<p><strong>Step 2: Find the subgrid button<\/strong><\/p>\n\n\n\n<p>Locate the <strong>Add New<\/strong> button in the subgrid ribbon. This is the button users click to create a new related record.<\/p>\n\n\n\n<p>Right-click the button and select <strong>Customize Command<\/strong> to inspect the command associated with it.<\/p>\n\n\n\n<p><strong>Step 3: Check the existing enable rules<\/strong><\/p>\n\n\n\n<p>In the command configuration, look at the existing enable rules.<\/p>\n\n\n\n<p>You may find the following rule:<\/p>\n\n\n\n<p>Mscrm.EntityFormIsEnabled<\/p>\n\n\n\n<p>This rule checks whether the form is enabled. If the rule returns false, the command is disabled.<\/p>\n\n\n\n<p><strong>Step 4: Use the existing rule<\/strong><\/p>\n\n\n\n<p>Now select your custom button and right click on that and select Customize Command. Now go to command for your button and add this rule under Enabled rule like below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2026\/10\/enabledbutton.png\"><img decoding=\"async\" loading=\"lazy\" width=\"498\" height=\"306\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2026\/10\/enabledbutton.png\" alt=\"\" class=\"wp-image-4806\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2026\/10\/enabledbutton.png 498w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2026\/10\/enabledbutton-300x184.png 300w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/a><\/figure>\n\n\n\n<p><strong>Important:<\/strong> This approach relies on the form&#8217;s enabled state. It does not directly check any custom status or Status Reason field. If you need to hide the button based on a specific business status while the form remains enabled, you have to use custom rule.<\/p>\n\n\n\n<p><strong>Step 5: Save, publish, and test<\/strong><\/p>\n\n\n\n<p>Save your changes in Ribbon Workbench and publish the customizations.<\/p>\n\n\n\n<p><strong>Summary<\/strong><\/p>\n\n\n\n<p>This way we can use out of the box rule to hide\/show our custom button so before writing custom code check if we can use something out of the box to implement our requirement.<\/p>\n\n\n\n<p>Hope it will help someone!!<br><strong>Keep learning and Keep Sharing!!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In Model driven apps, we sometimes need to show or hide a button on a subgrid based on the status of the parent record. For example, we have an Account entity and a related Contact entity. Users can add contract lines from a subgrid on the Contract form. Our requirement is simple: We can achieve this by writing a&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4804\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":4806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,402,522,25],"tags":[1175,1176],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4804"}],"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=4804"}],"version-history":[{"count":3,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4804\/revisions"}],"predecessor-version":[{"id":4808,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4804\/revisions\/4808"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/4806"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}