How to Show/Hide subgrid button based on some condition

How to Show/Hide subgrid button based on some condition

Step 1: Create a JavaScript webresource that contains the function:

function ValidateSubgridRecord(context) {
debugger;
var count = 0;
//Replace the subgrid name in below
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("Transaction") != null
&& Xrm.Page.getControl("Transaction") != undefined) {
count = Xrm.Page.getControl("Transaction").getGrid().getTotalRecordCount();
}
if (count > 1) {
Xrm.Page.ui.setFormNotification("You cannot add more then 1 Record", "INFO",
"2001"); // Set notification
//context.getEventArgs().preventDefault();
return false;
}
else {
Xrm.Page.ui.clearFormNotification("2001"); // Clear notification
return true;
}
}

Step 2: Add the child entity that you want to change the sub-grid behavior for to a solution. Also, add the webresource with the javascript function above and then load the solution into the Ribbon Workbench.

Open Ribbon WorkBench and load Child Entity. From the Subgrid section, select Add New Button and Right Click and Select Customize Command.

image1

Step 3: Click on the + button, and right Panel, Select + Add step. It will open the Panel; select CustomRule.

image2

Next, Give FunctionName and add WebResource.

image3

Step 4: Click on Command and Add Enable Rule.

image4

Step 5: Click Publish

Step 6: Redirect to the Form and Test solution.

image5

All product and company names are trademarks™, registered® or copyright© trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Riddhi Faldu

Riddhi Faldu

Riddhi is a firm believer of serenity and writing is something that keeps her grounded. Being a Computer Engineer by qualification, understanding and writing about tech comes to her naturally. It wouldn't be wrong to call her diligent as she likes pushing herself and others to bring the best on table. In leisure time, she likes practicing calligraphy and wishes to master the beautiful concoction of ink and words.

Read Related Blogs About Dynamics 365 Portal

How to Clear the Cache in the Power Apps Portal

How to Clear the Cache in the Power Apps Portal

3 Min
Revolutionizing Financial Services with Dynamics 365 Customer Portal

Revolutionizing Financial Services with Dynamics 365 Customer Portal

5 Min
Why You Need D365 Developers in Your Team

Why You Need D365 Developers in Your Team

4 Min
To Top