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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Count the number of record

(0) ShareShare
ReportReport
Posted on by

Hi,is it possible the count the number of records of an entity with javascript,can anyone please tell me how to do that if it possible

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    I think following post should be able to help you.

    http://www.customerdynamics.com/Blog/Get-the-Entities-and-their-Record-Counts-in-Microsoft-CRM/

    I would suggest having REST endpoints and not to access Database directly

  • Suggested answer
    Community Member Profile Picture
    on at
  • Community Member Profile Picture
    on at

    @Inder Singh Rathore.can you please tell me where i have to put that code.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Youssef,

    From which application/Interface/Solution/Form etc you are calling it?

  • Community Member Profile Picture
    on at

    i want call it inside account record

  • Suggested answer
    MehrCrm Profile Picture
    290 on at

    Using XrmServiceToolkit (https://xrmservicetoolkit.codeplex.com/) library, the GetAccountsCount function will return count of all accounts. You can add filters to the fetch to only fetch count of active or inactive accounts.
    Place the function in a JavaScript file and add it to the form and simple call:

    var countofAccounts = GetAccountsCount();
    
    function GetAccountsCount() {
    var fetchXml =
    	"<fetch mapping='logical' aggregate='true'>" +
                "<entity name='account'>" +
    	    "<attribute name='accountid' aggregate='count' alias='count' />" +
    	"</fetch>";
    	var result = XrmServiceToolkit.Soap.Fetch(fetchXml, false);
    	if((result) && (result.length) && (result.length > 0)) {
    	    return result[0].attributes["count"].value;
    	}
    	// Something is wrong
    	return -1;
    }


  • Community Member Profile Picture
    on at

    function totalcount() {

    var xml = "<fetch version='1.0' mapping='logical' aggregate='true'>" +
    "<entity name='entityname'>" +

    "<attribute name='atributeid'/>" +

    "<attribute name='atributeid' aggregate='COUNT' alias='count'/>"+

    " </entity>"+
    "</fetch>";

    var userRecords = XrmServiceToolkit.Soap.Fetch(xml);

    var count = userRecords[0].attributes.count.value;

    alert("Count= " + count);

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans