web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

get totalrecordcount in the subgrid

(0) ShareShare
ReportReport
Posted on by

0572.help.PNG

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sreevalli Profile Picture
    3,264 on at

    Hi Mahesh,

    I think form is loading before subgrid loads.

    You can get number of rows in supported way using Xrm.Page.getControl("gridname").getGrid().getTotalRecordCount() by adding timeout before for the javascript code because subgrid takes some time to load after the form is loaded.

    example:

    setTimeout("RetrieveSubGridRecords();", 2500);

  • Community Member Profile Picture
    on at

    thanks, but the most recent record should populate in the other field

  • Community Member Profile Picture
    on at

    thanks, but the most recent record from subgrid it should populate in the other field

  • Verified answer
    necsa Profile Picture
    3,455 on at

    Hi, Please try this code:

    function getTotalGridRecordCount(executionContext){

    debugger;

    try{

    setTimeout(function(){

    var formContext=executionContext.getFormContext();

    if(formContext.getControl("GridName")!=null && formContext.getControl("GridName")!=undefined){

    var count=formContext.getControl("GridName").getGrid().getTotalRecordCount();

    alert("total record in Grid: " + count);

    }

    },5000);

    }

    catch(e){

    var alertOptions={height:120,width:260};

    Xrm.Navigation.openAlertDialog(e.message,alertOptions).then(function(){});

    }

    }

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    In case you want to show count in some other field then why you are not using rollup field.

    CRM will calculate no of records from related subgrid and count will be shown in rollup field.

    User can manually refresh this field whenever they need to see count otherwise CRM will recalculate this field every hour.

    Here are more details on rollup field

    docs.microsoft.com/.../define-rollup-fields  

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Mahesh,

    Please have a look Rawish blog , its working and make sure if your environment is slow then increase timeout 500 to 1000 or 2000.

    community.dynamics.com/.../count-total-subgrid-records-in-dynamics-crm-using-javascript

    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

Responsible AI policies

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

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ZS-27011425-0 Profile Picture

ZS-27011425-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans