Skip to main content

Notifications

Announcements

No record found.

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
    CU06121650-0 Profile Picture
    CU06121650-0 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
    Aditya 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
    T.Koller 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
    Bipin D365 28,964 Super User 2024 Season 1 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

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans