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 :
Customer experience | Sales, Customer Insights,...
Suggested answer

UCI Subgrid getTotalRecordCount() returns 0 records

(0) ShareShare
ReportReport
Posted on by 145

hi,

I'm using a little javascript to count the records in a subgrid.

the sdk has this function:

context.getFormContext().getControl("mysubgrid").getGrid().getTotalRecordCount()

this function returns always 0 if the subgrid is on another tab (which is not loaded, yet).

If i navigate to that tab, subgrid loads, and getTotalRecordCount() returns the right result.

Any ideas on that issue?

best regards

I have the same question (0)
  • Suggested answer
    CU06121650-0 Profile Picture
    6 on at
    UCI Subgrid getTotalRecordCount() returns 0 records
    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
    Aditya Profile Picture
    260 on at
    RE: UCI Subgrid getTotalRecordCount() returns 0 records

    Hi T.Koller,

    If the below code is not working :-
    var totsubgrid= formContext.getControl("mysubgrid").getGrid().getTotalRecordCount();

    There is an alternative way to retrieve the subgid entity records which are associated with the current record :-

    var recordId = formContext.data.entity.getId().replace(/\{|\}/g, "");
    Xrm.WebApi.retrieveMultipleRecords("subgrid_entity", "?$select=field1,field2&$filter=_subgrid_entity_value eq " + recordId).then(function success(results) {
    var totsubgrid = results.entities.length;

    }, function (error) {
    var message = "There was an error while trying to load the page. Try this action again. If the problem persists, contact your system administrator.";
    var details = {
    message: message,
    details: message + "\r\n\r\n" + error.message
    };
    Xrm.Navigation.openErrorDialog(details);
    });

    Please mark the answer as verified if it is useful to you!!

  • T.Koller Profile Picture
    145 on at
    RE: UCI Subgrid getTotalRecordCount() returns 0 records

    sorry but this can't be by design. If they allow you to put a subgrid on any tab they have to ensure that the sdk works fine.

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: UCI Subgrid getTotalRecordCount() returns 0 records

    Hi,

    I think this is by design. CRM loads components on form in lazy loading scheme.

    Not all components are loaded synchronously. It would be better if you keep your grid on default tab which is the first tab.

    If found helpful, Please mark my answer 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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 182

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 129 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans