How to Show/Hide subgrid button based on some condition
Create a Webresource in Solution which having a function and pass Paramcontext as a input to the function.
Let's condider the scenerio
If the rows records more than one then Hide the 'Create New ' button
function validate(paramContext) {
var cnt = 0
cnt = Xrm.page.getControl('subgrid_name').getGrid().getTotalRecordCount(); // get the total row count of subgrid
if (cnt > 2) {
Xrm.Page.ui.setFormNotification("You cannot add more then 2 Record", "INFO",
"2001");
return false;
} else {
Xrm.Page.ui.clearFormNotification("2001"); // Clear notification
return true;
}
}
Now open the XRM Toolbox,
Open Ribbon Workbench and load entity, From the Subgrid section, select Add New Button and Right Click and Select Customize Command.
Click on the + button, and right Panel, Select + Add step. It will open the Panel; select CustomRule.
Click on Command and Add Enable Rule.
Click Publish.
Redirect to the Form and Test Solution..

