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 :
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

  • Suggested answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    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.

  • T.Koller Profile Picture
    145 on at

    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
    Aditya Profile Picture
    260 on at

    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!!

  • Suggested answer
    CU06121650-0 Profile Picture
    6 on at
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 95

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 83 Most Valuable Professional

#3
11manish Profile Picture

11manish 65 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans