Use Dynamics WebAPI to get Record Count
Use Dynamics WebAPI to get Record Count
When working in an environment where tools like XrmToolbox are not available or allowed getting a total record count can be a real pain sometimes. One way of doing it just using the browser involves using the Dynamics WebAPI. This came in handy last time we were doing a data load on our production system and wanted to see the status of how many records had been imported.
Small Data Set ( < 5k)
If you are trying to get the count for 5,000 or less records. you can do a simple count on the data.
Format
/api/data/v9.0/<Entity Set Name>/?$count=true
Example
/api/data/v9.0/contacts/?$count=true
Data Returned
{"@odata.context":"https://org.crm.dynamics.com/api/data/v9.0/$metadata#contacts",
"@odata.count":3
,"value":
Large Data Set ( > 5k & < 50k)
If your record set will have 5k or more you can utilize the webapi by creating a FetchXml aggregate query, this does have a limitation of 50k records.
Query Format
/api/data/v9.0/<Entity Set Name>?fetchXml=<FetchXml query that has been URI encoded>
FetchXml Format
<fetch version="1.0" mapping="logical" aggregate="true"> <entity name="contact"> <attribute name="contactid" aggregate="count" alias="count" /> </entity> </fetch>
Encoding FetchXml
To encode the FetchXml you can open the Console window in your browser and utilize the encodeURI JavaScript function.
encodeURI('<fetch version="1.0" mapping="logical" aggregate="true"><entity name="contact"><attribute name="contactid" aggregate="count" alias="count" /></entity></fetch>')
Example
/api/data/v9.0/contacts?fetchXml=%3Cfetch%20version=%221.0%22%20mapping=%22logical%22%20aggregate=%22true%22%3E%3Centity%20name=%22contact%22%3E%3Cattribute%20name=%22contactid%22%20aggregate=%22count%22%20alias=%22count%22%20/%3E%3C/entity%3E%3C/fetch%3E
Data Returned
{"@odata.context":"https://org6744e6cd.crm.dynamics.com/api/data/v9.0/$metadata#contacts","value":
[{"count":3}]}
Excellent post, thanks for this. I gathered lots of information from this and I am happy about it. Do share more updates.
ReplyDeleteMicrosoft Dynamics crm Training in Chennai
Microsoft Dynamics Training
Microsoft crm Training
Hacking course in Chennai
Tally course in Chennai
PHP Training in Chennai
Web Designing Training in Chennai
Microsoft Dynamics crm Training in Anna Nagar
Microsoft Dynamics crm Training in Vadapalani
Microsoft Dynamics crm Training in Thiruvanmiyur
I found your blog on Google and read a few of your other posts. I just added you to my Google News Reader. You can also visit API Development And Integration for more Metricoid Technology Solutions related information and knowledge, Keep up the great work Look forward to reading more from you in the future.
ReplyDeleteExcellent blog thanks for sharing the valuable information..it becomes easy to read and easily understand the information.
ReplyDeleteUseful article which was very helpful. also interesting and contains good information.
to know about python training course , use the below link.
Python Training in chennai
Python Course in chennai
Your blog is awfully appealing. I am contented with your post. I regularly read your blog and its very helpful. If you are looking for the best Api Integration, then visit Neebal. Thanks! I enjoyed this blog post.
ReplyDeleteExcellent article and with lots of information. I really learned a lot here. Do share more like this.
ReplyDeleteWeb Designing Training in Chennai
Web Designing course Near Me
Web Designing Course in Bangalore
Web Developer course in Chennai
I read this blog, Nice article...Thanks for sharing and waiting for the next...
ReplyDeleteJava Programming Tutorial
java basic tutorial
Nice blog, very informative content.Thanks for sharing, waiting for the next update…
ReplyDeleteData Science Tutorial for Beginners
statistics tutorial for data science
Nice blog, very informative content.Thanks for sharing, waiting for the next update…
ReplyDeleteaws tutorial
learn aws
Really an informative blog...Thanks for sharing an informative article with us.
ReplyDeleteJapanese Classes in Chennai
Japanese Language Course in Chennai
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete