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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Using FetchXML with Li...
Power Automate
Answered

Using FetchXML with List records in CDS (current environment)

(1) ShareShare
ReportReport
Posted on by 382

Hello,

The new CDS (Current environment) connector's "List records" action appears to support FetchXML, however, it throws errors (500) when using aggregation.

Can anyone provide some kind of documentation reference?

Or test a basic scenario where you're pulling linked entities with an aggregation?

Categories:
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @Helpful 

     

    Please check the thread below https://powerusers.microsoft.com/t5/Building-Flows/Recurrence-Flow-Send-An-Email-action-for-outstanding-orders/td-p/308592

     

    Here the XRM toolbox has been used to generate the fetchxml query to create a filter to get records. 

     

    Please share a screenshot of the flow that you have built so far so that we can better assist you. 

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Helpful Profile Picture
    382 on at

    Yep, using FetchXML Builder to construct the XML.  In the tool, it retrieves the records exactly as designed.  In the Flow, however, it throws an error.  My query includes aggregation.

    • When I test without aggregation, it executes in 1s and brings linked entities and everything back as it should
    • When I test WITH aggregation I get an error that includes:  
      "body":{"_error":{"Code":null,"Description":"Key property 'zco_projectbudgetid' of type 'Microsoft.Dynamics.CRM.zco_projectbudget' is null. Key properties cannot have null values."The working screenshot:

    Any ideas would be welcome.

    A screenshot of the working query - no aggregation:working_no_aggregation.png

     

    A screenshot of the failing query with aggregation (note that in this screenshot I removed the attributes from the root just to see if I got a different result)

    distinct="true" returntotalrecordcount="true"

    :failing_aggregation.png

     

  • Helpful Profile Picture
    382 on at

    Here's the XML if you'd like to test something similar:

    <fetch distinct="true" aggregate="true" returntotalrecordcount="true" >
     <entity name="zco_projectbudget" >
     <attribute name="zco_projectbudgetid" alias="ProjectBudgetId" groupby="true" />
     <filter type="or" >
     <condition attribute="statuscode" operator="eq" value="1" />
     <condition attribute="statuscode" operator="eq" value="796500002" />
     <condition attribute="statuscode" operator="eq" value="796500003" />
     </filter>
     <link-entity name="zco_project" from="zco_projectid" to="zco_projectid" >
     <link-entity name="zco_worker" from="zco_workerid" to="zco_projectmanagerid" >
     <attribute name="zco_primaryemail" alias="ProjectManagerEmail" groupby="true" />
     </link-entity>
     </link-entity>
     <link-entity name="zco_projectbudgetline" from="zco_projectbudgetid" to="zco_projectbudgetid" link-type="outer" >
     <attribute name="zco_projectbudgetlineid" alias="ProjectBudgetLineId" groupby="true" />
     <attribute name="zco_budgetline_amount" alias="BudgetLineAmount" groupby="true" />
     <filter>
     <condition attribute="statuscode" operator="eq" value="1" />
     </filter>
     <link-entity name="zco_budgetlineperiod" from="zco_projectbudgetlineid" to="zco_projectbudgetlineid" link-type="outer" >
     <attribute name="zco_amount" alias="BudgetPeriodsAmount_Sum" aggregate="sum" />
     <filter>
     <condition attribute="statuscode" operator="eq" value="1" />
     </filter>
     </link-entity>
     </link-entity>
     </entity>
    </fetch>
  • LeeHarris Profile Picture
    1,026 on at

    Hi @Helpful

    Did you have any luck solving this? I am seeing the same issue when using aggregation in fetchxml.

     

  • Helpful Profile Picture
    382 on at

    Hey @LeeHarris,

    I ended up putting a roll-up field on the records I was concerned about and then querying for records with a certain value in the roll-up.

    Got the result I wanted, but seems like an unecessary workaround.

  • LeeHarris Profile Picture
    1,026 on at

    Hi @Helpful 

    Rollups are unfortunately not an option for me due to the limit of 10 per entity, already maxed this out.

    Thanks for letting me know anyway.

     

     

  • Verified answer
    Helpful Profile Picture
    382 on at

    I have identified a workaround:  the alias of the key property MUST be the same name as the attribute.

     

    For example:

    <fetch aggregate="true" >
     <entity name="contact">
     <attribute name="contactid" alias="contactid" groupby="true" />
     <attribute name="annualincome" alias="AnnualIncome_sum" aggregate="sum" />
     </entity>
    </fetch>

     

    In my view this is still a defect, but for anyone that is stuck on this I hope it saves you many, many hours.

  • MattRitchie Profile Picture
    8 on at

    Has FetchXml gone away

  • Helpful Profile Picture
    382 on at

    I hope not because we have stuff that depends on it!

    If you’re not seeing it on your List Records action make sure you’re using the CDS (current environment) connector.

  • MattRitchie Profile Picture
    8 on at

    Thanks for the tip. I found it. This is amazing and powerful. So much easier tha

    n odata inside flow

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 355

#2
11manish Profile Picture

11manish 336 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard