CRM Crate

How to get the total record count of a grid in Dynamics 365?

We will learn to get the total record count of a grid in Dynamics 365. Before we start, make sure to subscribe to CRM Crate so that you stay up to date in the field of Dynamics 365.

How to get the total record count of a sub-grid in Dynamics 365

Using getTotalRecordCount  client API –

We will use the getTotalRecordCount  client Web API for getting the total number of row count present in the sub-grid.

getTotalRecordCount (Client API reference)

Returns the total number of records that match the filter criteria of the view, not limited by the number visible in a single page.
1. When the Dynamics 365 for Outlook client isn’t connected to the server, this number is limited to those records that the user has selected to take offline.
2. For Dynamics 365 mobile clients, this method will return the number of records in the subgrid.

JavaScript code for retrieving total number of rows from a sub-grid –

We will use the below JavaScript snippet to get the total number of rows from a sub-grid using the getTotalRecordCount client Web API.

//CRM Crate - JavaScript Snippet
function CallMethod (executionContext) {
//Reading Attribute Value From The Form.
var formContext = executionContext.getFormContext();
var Input = formContext.getAttribute("cc_calculaterecordcount").getValue();
if(Input == true)
{
//Get Grid Context
var gridContext = formContext.getControl("BusinessAccounts"); //Sub-Grid Name

//Getting Grid Row Count
let filteredRecordCount = gridContext.getGrid().getTotalRecordCount(); // Collect Total Row Count

//Setting Output Value In Field
formContext.getAttribute("cc_displaytotalcount").setValue(filteredRecordCount);
formContext.getAttribute("cc_calculaterecordcount").setValue(false);
}
}

Validate the changes in Dynamics 365

Once the above code is configured and published, navigate to the Dynamics 365 and validate the changes as shown below.

Thus, learned to get the total record count of a sub-grid in Dynamics 365.

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.