Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

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

Posted on by 70

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
    CU06121650-0 Profile Picture
    CU06121650-0 6 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.
  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 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

  • Jane88 Profile Picture
    Jane88 80 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!

  • Ics_rthompsoneu Profile Picture
    Ics_rthompsoneu 70 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;
    
       }

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans