Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Get count of all records when the view is changed

Posted on by 275

Hello Experts

As we know, when an entity is opened we can see all records but for any default/changed view the count on bottom of the pages shows as 5000+ but not exact count. I was looking for a way to get the count as a pop-up when the view is changed or as a Ribbon button which throws a pop-up showing current views record count when clicked. 

*This post is locked for comments

  • Turbo Forms Profile Picture
    Turbo Forms 275 on at
    RE: Get count of all records when the view is changed

    I have tried something similar, I have got the count using a ribbon button to get the record count from the view filter selected and displays results on a pop-up

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Get count of all records when the view is changed

    You can use fetchXml to get aggregate functions.

    The following is a sample using C# code (retrieving count of emails), but you should be able to create the fetchXml string using JavaScript and Webapi to get that value:

           private int RetrieveEmailCount(Guid emailId)

           {

               int rc = 0;

               StringBuilder sb = new StringBuilder();

               sb.AppendLine("<fetch distinct='false' mapping='logical' aggregate='true'> ");

               sb.AppendLine(" <entity name='email'> ");

               sb.AppendLine("  <attribute name='activityid' alias='email_count' aggregate='count'/> ");

               sb.AppendLine(" </entity> ");

               sb.AppendLine("</fetch>");

               EntityCollection totalCount = service.RetrieveMultiple(new FetchExpression(sb.ToString()));

               if (totalCount.Entities.Count > 0)

               {

                   foreach (var t in totalCount.Entities)

                   {

                       rc = (int)((AliasedValue)t["email_count"]).Value;

                       break;

                   }

               }

               return rc;

           }

    So, you have two options: use the rest api or call an action to get you the results. Regardless of the option, you will need to use Ribbon Workbench to add you script to the home page.

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans