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

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

How to get the row grid count not working in Unified Interface

(1) ShareShare
ReportReport
Posted on by

Hi

I am using the Unified Interface.  I can't seem to get the grid count to work anymore.

function getGridRowCount(formContext, gridControl) {
   var subGrid = formContext.getControl(gridControl).getGrid();
   var subGridRows = subGrid.getRows().getLength();
   return subGridRows;
}

  • Suggested answer
    RaviKashyap Profile Picture
    on at
    RE: How to get the row grid count not working in Unified Interface

    Hi,

    Try using getTotalRecordCount method instead of length.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/grids/grid/gettotalrecordcount

    Hope this helps.

  • Ics_rthompsoneu Profile Picture
    on at
    RE: How to get the row grid count not working in Unified Interface

    I changed my code still not working.

    I am wondering if the problem has to do with the sections appearing as "Tabs" in UI.

       export function getGridRowCount(formContext, gridControl) {
    
           var gridContext = formContext.getControl(gridControl);
    
           var totalSubGridRows = (gridContext).getGrid().getTotalRecordCount();
    
           return totalSubGridRows;
    
       }

  • Jane88 Profile Picture
    on at
    RE: How to get the row grid count not working in Unified Interface

    we have the same issue. the length always return 0 in UCI.

    We try to get the attribute from each row. But the forEach never executed.

    var rows = formContext.getControl(xxx_SUBGRID).getGrid().getRows();

    rows.forEach(function (row, i) {

                    var text = row.data.entity.getPrimaryAttributeValue();

               });

    Please help to fix the issue!

    Thanks!

  • Suggested answer
    Henry J. Profile Picture
    on at
    RE: How to get the row grid count not working in Unified Interface

    There are multiple things here,

    As Ravi Kashyap explained, the proper method is the getTotalRecordCount.

    So this should work:

    var formContext = executionContext.getFormContext(); // get the form Context
    var gridContext = formContext.getControl("contacts"); // get the contacts subgrid context
    var filteredRecordCount = gridContext.getGrid().getTotalRecordCount();

    Now as Ics_rthompsoneu suggested, subgrids and web resources within tabs are not loaded until the tab is displayed.

    This is by design to optimize performances. Have you referred to that article?

    https://docs.microsoft.com/en-us/powerapps/maker/model-driven-apps/optimize-form-performance#form-scripts

    Use collapsed tabs to defer loading web resources
    When web resources or IFRAMES are included in sections inside a collapsed tab they will not be loaded if the tab is collapsed. They will be loaded when the tab is expanded. When the tab state changes the TabStateChange event occurs. Any code that is required to support web resources or IFRAMEs within collapsed tabs can use event handlers for the TabStateChange event and reduce code that might otherwise have to occur in the OnLoad event.

    Henry

  • Suggested answer
    CU06121650-0 Profile Picture
    on at
    How to get the row grid count not working in Unified Interface
    I was trying to SHOW the section the subgrid was in if it contained at least one record, but getTotalRecordCount always returned zero. I fixed this by showing the section with the subgrid by default and HIDING it if there were no rows. Seems like if the grid isn't displayed then the rows in the grid aren't recognized. Thought I'd mention this since I'd only seen mention of the Tab being displayed by default and not the section.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans