'Dynamic 365, get owner of a record with FetchXML / C#

How do I retrieve owner of a record (for example a task) with FetchXML or C#?

I can connect the two tables task and owner with FetchXML :

<fetch>
  <entity name="task">
    <link-entity name="owner" from="ownerid" to="ownerid" />
  </entity>
</fetch>

But I'm not sure how to connect further. The record I'm testing with is systemuser which I know and guess is contact. But where is the guid for contactid?



Solution 1:[1]

After a bunch of google searches I found the answer. The owner of a task can't be contact, but systemuser. So this is the FetchXML I created

The following code gives me a result of systemusers and teams owned by tasks.

<fetch>
  <entity name="task">
    <attribute name="scheduledend" />
    <attribute name="subject" />
    <filter>
      <condition attribute="scheduledend" operator="le" value="2022.05.04" />
      <condition attribute="statecode" operator="eq" value="0" />
    </filter>
    <link-entity name="systemuser" from="systemuserid" to="ownerid" link-type="outer" alias="sysuser">
      <attribute name="internalemailaddress" />
    </link-entity>
    <link-entity name="team" from="teamid" to="ownerid" link-type="outer" alias="team">
      <attribute name="emailaddress" />
    </link-entity>
    <link-entity name="contact" from="contactid" to="regardingobjectid" link-type="outer" alias="contact">
      <attribute name="fullname" />
    </link-entity>
    <link-entity name="account" from="accountid" to="regardingobjectid" link-type="outer" alias="accout">
      <attribute name="name" />
    </link-entity>
  </entity>
</fetch>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2980838