Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Need to retrieve the lookup counts through web api

Posted on by 5

Team , I need to get the lookup count through web api.

For ex : we have a case entity.In case entity owner A having 20 cases and Owner B having 30 cases.

Now I need to get the count of cases based on the owner lookup.

expected Json

"value":[{"owner":Owner A,"COUNT":20},{"owner":Owner B,"COUNT":30}]


If I try this for getting the status(optionset) count by using /api/data/v9.1/incidents?$apply=groupby((statuscode),aggregate($count%20as%20COUNT)).It will return the count.

"value":[{"statuscode":19090909,"COUNT":45},{"statuscode":2121232,"COUNT":8}]

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Need to retrieve the lookup counts through web api

    Hi partner,

    1.You could use /api/data/v9.1/incidents?$apply=groupby((ownerid),aggregate($count%20as%20COUNT).

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-data-web-api

    2.You can search through Web api with Owner as the search criteria, and the count of results is what you want. (But you could only get only one result of an owner each  time).

    function GeteCount (executionContext) {
        var formContext = executionContext.getFormContext();
        var currentUserRoleIds = Xrm.Utility.getGlobalContext().userSettings.securityRoles;
        for (i=0i<currentUserRoleIds.lengthi++) {
          var currentRoleUniqueId = currentUserRoleIds[i];
          Xrm.WebApi.retrieveRecord("incident","?$select=subject&$filter=ownerid eq '"+"ownerid"+"'").then(
            function success(result) {
                var count=result.count;
                //..todo set the value to lookup field
      },
            function error (error) {
              Xrm.Navigation.openAlertDialog({ text: error.message });
            }
      );}
        
    }

    Hope it helps.

    Best Regards,

    Leo

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans