ルートエンティティと複数の子を取得する単一のFetchXMLクエリを作成することは可能ですか?私ができることは1:1だけです。
4 に答える
私が質問を誤解しない限り、これは非常に可能です。
たとえば、特定のアカウントに関連するすべての連絡先を検索する必要があります。これは、アカウントへの連絡先の親顧客ルックアップによってCrmで表されます。
<fetch mapping="logical" count="100" version="1.0">
<entity name="account">
<attribute name="name" />
<link-entity name="contact" from="parentcustomerid" to="accountid">
<attribute name="fullname" />
</link-entity>
</entity>
</fetch>
これにより、次のような結果セットが得られます。
<resultset morerecords="0" paging-cookie="<cookie page="1"><accountid last="{E704FAD6-2D4B-E111-9FED-00155D828444}" first="{AD912122-6B3C-E111-9B37-00155D828444}" /></cookie>">
<result>
<name>RGD Mining Inc</name>
<accountid>{E704FAD6-2D4B-E111-9FED-00155D828444}</accountid>
<accountid.fullname>Bill Miner</accountid.fullname>
</result>
<result>
<name>RGD Mining Inc</name>
<accountid>{E704FAD6-2D4B-E111-9FED-00155D828444}</accountid>
<accountid.fullname>Green</accountid.fullname>
</result>
</resultset>
ジェームズウッドは正しいです。Fetch XMLは再帰的であるため、リンクエンティティを使用することで、必要な情報を取得できます。
たとえば、次のようになります。
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="account">
<attribute name="name" />
<attribute name="primarycontactid" />
<attribute name="telephone1" />
<attribute name="accountid" />
<order attribute="name" descending="false" />
<link-entity name="contact" from="parentcustomerid" to="accountid" alias="aj">
<attribute name="firstname" />
<attribute name="lastname" />
<attribute name="telephone1" />
<link-entity name="businessunit" from="businessunitid" to="owningbusinessunit" alias="ak">
<attribute name="name" />
<attribute name="address1_line1" />
<attribute name="address1_line2" />
<attribute name="address1_line3" />
<filter type="and">
<condition attribute="name" operator="not-null" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
あなたの質問が本当に「単一のルートエンティティと複数の子を取得する単一のFetchXMLクエリを書くことは可能ですか」である場合、残念ながら答えはノーです。ただし、ルートデータの重複を処理できる場合(たとえば、SSRSレポートのグループ化機能を使用)、必要なことは完全に可能です。
いいえ、できません。
それが可能であることを報告できてうれしいです。私にはうまくいった解決策があります。
唯一の注意点は、複数の子アカウントがある場合、親に対して複数の結果が得られることです。例えば:
parent 1: child 1
parent 2: child 1
parent 2: child 2
つまり、結果を並べ替え関数で実行して、親の下にあるすべての子を多次元配列で取得するか、すべてのアカウントをフラット配列で一意のエントリとして取得する必要があります。
また、これは1レベルだけ下がります。階層がマルチレベルの場合、このコードを変更する必要があります。
<fetch distinct="false" mapping="logical">
<entity name="account">
<attribute name="name" />
<link-entity name="account" alias="childaccount" to="accountid" from="parentaccountid" link-type="outer">
<attribute name="name" alias="childname" />
</link-entity>
</entity>
</fetch>