Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Client API subgrid getGrid().getTotalRecordCount() always returns 0

(2) ShareShare
ReportReport
Posted on by 99
I have the below code running to popup a warning if a subgrid contains data.
 
However, the row count always returns 0 even when there is data in the subgrid.
 
I found another post where there was a suggestion that the subgrid MUST be on the summary tab of the form, so i moved the subgrid and still it returns 0.
 

 

function AssetAdvisoryWarning(executionContext) {   

var formContext = executionContext.getFormContext();   

var gridContext = formContext.getControl(/asset_advisories/);   

var myRows = gridContext.getGrid().getTotalRecordCount();   

console.log(/row count (/+myRows+/)/)   

if (myRows > 0) {       

formContext.ui.setFormNotification(/This asset has (/+myRows+/) advisories./, /WARNING/);   

}

}

  • Suggested answer
    CU06121650-0 Profile Picture
    CU06121650-0 6 on at
    Client API subgrid getGrid().getTotalRecordCount() always returns 0
    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
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    Client API subgrid getGrid().getTotalRecordCount() always returns 0
    Hi barryjarvis,
     
    The retrieveMultipleRecords Client API is outlined here.
    Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);
    Name Type Required Description
    entityLogicalName String Yes The table logical name of the records you want to retrieve. For example: account.
    options String No OData system query options or FetchXML query to retrieve your data. See Options
    maxPageSize Number No Specify a positive number that indicates the number of table records to be returned per page. If you don't specify this parameter, the value is defaulted to the maximum limit of 5000 records.



    If the number of records being retrieved is more than the specified maxPageSize value or 5000 records, nextLink column in the returned promise object will contain a link to retrieve records.
    successCallback Function No A function to call when table records are retrieved. See Return Value
    errorCallback Function No A function to call when the operation fails.
      
      "msdyn_customerasset" is the correct entityLogicalName. 
     
    The following system query options are supported: $select, $top, $filter, $expand, and $orderby. You can use the $filter query option to return only the records linked through the asset_advisories subgrid. Alternatively specify a FetchXML query by using the fetchXml column to specify the query. e.g.
     
    var fetchXml = "?fetchXml=<fetch mapping='logical'><entity name='msdyn_customerasset'></entity></fetch>";
    
    Xrm.WebApi.retrieveMultipleRecords("msdyn_customerasset", fetchXml).then(
        function success(result) {
            for (var i = 0; i < result.entities.length; i++) {
                console.log(result.entities[i]);
            }                    
    
            // perform additional operations on retrieved records
        },
        function (error) {
            console.log(error.message);
            // handle error conditions
        }
    );
    The fetchXml variable will need to be modified so that it only returns records msdyn_customerasset records related to the parent table.
     
  • barryjarvis Profile Picture
    barryjarvis 99 on at
    Client API subgrid getGrid().getTotalRecordCount() always returns 0
    Thanks for the reply. Not sure why i can't reply to your post though?
     
    Anyway, i tried that new method, and i'm getting an error that it can't find the subgrid.
     
    "Could not find a property named 'asset_advisories' on type 'Microsoft.Dynamics.CRM.msdyn_customerasset'."
     

    The name of the subgrid is 'asset_advisories' and it sits on the default form in the standard 'msdyn_customerasset' table.

    Is there a different subgrid name that gets assigned that i'm missing? I'm also assuming it's the logical name i need to use for the Customer Asset table?

    The line of code where this property is selected is:

    Xrm.WebApi.retrieveMultipleRecords("msdyn_customerasset", "?$select=asset_advisories&$filter=_msdyn_customerasset_value eq " + recordId).then(function success(results) {
  • Verified answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    Client API subgrid getGrid().getTotalRecordCount() always returns 0
    hi barryjarvis,
    You can find an alternative solution here.

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

Product updates

Dynamics 365 release plans