Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at firstname.lastname@example.org
Sometimes the finest of functionalities escape our eye. And this is really one such feature in Dynamics 365 Web API. And I discovered when a requirement came along.
The requirement was to fetch all incidents which does not have any open tasks. In other words we have to find incidents in Dynamics 365 that have all associated tasks closed.
A bit of searching and finally came across this Microsoft Docs article.
WebAPI in-fact support lambda queries. As of now there are couple of these operators – any and all. It was such a delight to learn about them. Such a treat that WebAPI have some really powerful query operators in its kitty.
So coming back to my requirement – How do I accomplish this? The below query is what I need to accomplish this. It returns only those incidents which have all associated tasks closed.
<Your Organization URL>/api/data/v9.1/incidents?$select=title&$filter=Incident_Tasks/all(o:o/statecode eq 1)
Simple isn’t it? You can use the same query for other activities as well.
Hope this helps!