Quick Tip: Resolving Error Retrieving Teams via Fetchxml with List Records Action in CDS (Current Environment) Connector

I ran into a rather odd error recently when I was trying to use a FetchXML query to retrieve a list of Teams using the List Records action with the Common Data Service (Current Environment) Connector in a Power Automate flow, so to save you any future headaches I’ve outlined the issue below and the solution to the problem.

The Problem

In this instance I needed to retrieve a list of Teams related to Accounts that matched a specific N:N relationship. As this involved an N:N relationship, there are mulitple levels of link-entities and therefore we cannot use the normal OData filter query parameters.

The FetchXML query I created, using Jonas Rapp’s FetchXML Builder, was:

<fetch>
  <entity name="team" >
    <attribute name="teamid" />
    <link-entity name="account" from="accountid" to="regardingobjectid" >
      <link-entity name="cn_cn_practice_account" from="accountid" to="accountid" >
        <link-entity name="cn_practice" from="cn_practiceid" to="cn_practiceid" >
          <filter>
            <condition attribute="cn_name" operator="eq" value="Investment" />
          </filter>
        </link-entity>
      </link-entity>
    </link-entity>
  </entity>
</fetch>

I tested this query and it returned a valid list of results:

I then took the FetchXML query and added it to my List Records action and ran my Flow, so imagine my surprise when it failed!

The important part of the error details that were returned is below:

[Key property 'ownerid' of type 'Microsoft.Dynamics.CRM.team' is null. Key properties cannot have null values.]

The only problem with this error is that there is no “ownerid” property on a Team…

The SOLUTION

I was banging my head off my table trying to solve this issue and I was stumped, so I reached out to the community to see if anyone else had any ideas; fortunately for me Rob Dawson stepped up to the table with a genius idea; he suggested faking the ownerid as an alias for the administratorid attribute. This would literally never have occurred to me, so I’m extremely grateful for his help!

I added the new FetchXML query, with the ownerid alias for the administratorid attribute and, hey presto, it worked!

Conclusion

This was actually a relatively simple workaround for what appears to be a bug in the List Records step, but hopefully you’ll find it useful too! I’m always grateful to be part of a community that can help me when I’m stuck, and scenarios like this show how important it is to have a great network of peers to help you see solutions that wouldn’t otherwise occur to you

Published by

4 thoughts on “Quick Tip: Resolving Error Retrieving Teams via Fetchxml with List Records Action in CDS (Current Environment) Connector

Leave a comment