Hi,
I would like to check if my subgrid contains any records and then if it's empty I want it to be invisible with a script. I'm also asking myself where can I see the exact ID of my subgrid ?
Regards,
Antoine
*This post is locked for comments
Hi,
I would like to check if my subgrid contains any records and then if it's empty I want it to be invisible with a script. I'm also asking myself where can I see the exact ID of my subgrid ?
Regards,
Antoine
*This post is locked for comments
If you got the answer, please close the thread as verified.
THANKS YOU SO MUCH IT WORK PERFECTLY !!
Hi Antoine,
Here the subgrid name is children_subgrid.
Please set a timeout function to ensure that the subgrid is loaded.
Change the code as below.
function CheckRows() { var grid = Xrm.Page.getControl("children_subgrid"); if (grid == null) { //make sure the grid has loaded setTimeout(function () { CheckRows(); }, 2000); //if the grid hasn’t loaded run this again when it has return; } var filteredRecordCount = grid.getGrid().getTotalRecordCount(); if (filteredRecordCount == 0) { grid.setVisible(false); } }
Antoine,
What is the name of the subgrid in the form? Can you share a screenshot of the Set Properties window.
The code seems good but i get an error and i don't know why, when i subsitute "subGridgridName" by my own SubGrid name, do i have to put the publisher prefix ? (xx_subGridgridName or just subGridgridName ?), does this code work for you ?
Thanks you anyway
Hi Antoine,
Try using the following code.
function CheckRows() { var grid = Xrm.Page.getControl("subGridgridName"); var filteredRecordCount = grid.getGrid().getTotalRecordCount(); if (filteredRecordCount == 0) { grid.setVisible(false); } }
For getting the subgrid name, go to Form Editor. Select the subgrid and click Change Properties in the command bar as shown in the screenshot below.
In the Set Properties window that appears, we can get the name of the subgrid as highlighted below.
Hope this helps.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156