Notifications
Announcements
*This post is locked for comments
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);
thanks, but the most recent record should populate in the other field
thanks, but the most recent record from subgrid it should populate in the other field
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(){});
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
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
ZS-27011425-0 1