FetchXML 查询以从多个链接实体中获取列

FetchXML Query to fetch columns from multiple Linked Entity

场景:有一个在网格中显示数据的门户,该数据来自 Dynamics 365。正在开发 Dynamics,我被要求提供一个查询,它将在网格中显示数据以下格式

例如,Phone 调用可以与联系人或 CustomAccount(自定义实体)相关联,并且 CustomAccount 在其表单上查找联系人。我们需要所有 Phone 通话记录,但有一个问题。在获取 Phone 联系人电话时,我们需要获取联系人的字段值,如住宅地址、邮寄地址、电子邮件地址、Phone 号码。这是可行的。但是,如果 Phone 调用与 CustomAccount 实体关联,那么我们必须获取与 CustomAccount 实体关联的联系人,然后获取其字段,如住宅地址、邮寄地址、电子邮件地址、Phone 号码。

我尝试构建查询,但结果很奇怪,只显示 Phone 与 CustomAccount 实体关联的调用,而不是联系实体。

<fetch>
  <entity name='phonecall' >
    <all-attributes/>
    <link-entity name='contact' from='contactid' to='regardingobjectid' link-type='outer' alias='contact' >
      <all-attributes/>
    </link-entity>
    <link-entity name='pref_CustAccount' from='pref_CustAccountid' to='regardingobjectid' link-type='outer' alias='account' >
      <link-entity name='contact' from='contactid' to='lpl_clientid' link-type='inner' alias='accountcontact' >
        <all-attributes/>
      </link-entity>
    </link-entity>
  </entity>
</fetch>

我刚刚在我的 CRM 实例上复制了您的场景。我认为你的问题是 Link type for below line.

 <link-entity name='contact' from='contactid' to='lpl_clientid' link-type='inner' alias='accountcontact' >

你需要外在而不是内在。 当我给出 inner 时,我只得到了与上一行相关的那些记录。

这是我的完整抓取

<fetch>
  <entity name="phonecall" >
    <link-entity name="contact" from="contactid" to="regardingobjectid" link-type="outer" alias="directcontact" >
      <attribute name="fullname" />
    </link-entity>
    <link-entity name="account" from="accountid" to="regardingobjectid" link-type="outer" alias="account" >
      <link-entity name="contact" from="contactid" to="primarycontactid" link-type="outer" alias="primarycontact" >
        <attribute name="fullname" />
      </link-entity>
    </link-entity>
  </entity>
</fetch>