web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Check if a subgrid is empty and then display it or not

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    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.

    65576.2.PNG

    In the Set Properties window that appears, we can get the name of the subgrid as highlighted below.

    65576.2.PNG

    Hope this helps.

  • Community Member Profile Picture
    on at

    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

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Antoine,

    What is the name of the subgrid in the form? Can you share a screenshot of the Set Properties window.

  • Community Member Profile Picture
    on at

    2477.Sans-titre.png

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    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);
        }    
    }
    
  • Community Member Profile Picture
    on at

    THANKS YOU SO MUCH IT WORK PERFECTLY !!

  • Nithya Gopinath Profile Picture
    17,078 on at

    If you got the answer, please close the thread as verified.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans