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.

Read Related Blogs About Dynamics 365 Portal

Importance of Dynamics 365 Portal for the Insurance Industry

Importance of Dynamics 365 Portal for the Insurance Industry

6 Min
PowerApps Portals: A Comprehensive Web Solutions

PowerApps Portals: A Comprehensive Web Solutions

5 Min
How to Apply Field-Level Security in System Fields in CRM?

How to Apply Field-Level Security in System Fields in CRM?

4 Min
To Top