Dynamics CRM 2011 : カスタムレポート その 2 - FetchXML を利用したカスタム活動レポート

みなさん、こんにちは。

今日は開発者の方向けの情報として、先日北米プレミアフィールドエンジニアチームブログで
公開された、FetchXML を利用したカスタム活動レポートについての記事を紹介します。

元情報: Dynamic Activity Reporting using FetchXML

===========================================================================
以前の記事で、フィルター化されたビューと FetchXML について紹介しました。今回はそれに
関連する情報を提供します。

最近オンライン環境を利用しているユーザーから、活動のレポートをカスタマイズしたいが、
以下の制限があるため、対処が困難であるという話をよく聞きます。

- データの取得で FetchXML のみサポートしている
- 既定のレポートはカスタマイズできない

今回あるユーザーより、選択した取引先企業に関連する営業案件、または取引先担当者を
関連を持った活動のみをレポートとして表示したいという要望を受け、実際にレポートの
開発を行いました。ここではその詳細を紹介します。

作成したレポートパラメータと対応するフィールド

@Accountid : Regardingobjectid

@EventDateFrom : Scheduledend

@EventDateTo : Scheduledend

@ActivityType : Activitytypecode

@Status : Statecode

FetchXML では link-type=’outer’ を利用することで、必要な列を取得しています。ただし
この種類の結合を利用する場合、パフォーマンスに影響がありますので、レポートの
必要性を十分に検討してください。

利用した FetchXML

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="activitypointer"> <attribute name="subject" /> <attribute name="ownerid" /> <attribute name="regardingobjectid" /> <attribute name="activitytypecode" /> <attribute name="statecode" /> <attribute name="scheduledstart" /> <attribute name="scheduledend" /> <attribute name="activityid" /> <attribute name="description" /> <attribute name="createdon" /> <attribute name="createdby" /> <attribute name="actualstart" /> <attribute name="actualend" /> <order attribute="modifiedon" descending="false" /> <filter type="and"> <condition attribute="regardingobjectid" operator="not-null" /> <condition attribute="isregularactivity" operator="eq" value="1" /> <condition attribute="statecode" operator="in" value="@Status" /> <condition attribute="activitytypecode" operator="in" value="@ActivityType" /> <filter type="and"> <condition attribute="scheduledend" operator="on-or-after" value="@EventDateFrom"/> <condition attribute="scheduledend" operator="on-or-before" value="@EventDateTo"/> </filter> </filter> <link-entity name="opportunity" from="opportunityid" to="regardingobjectid" alias="opp" link-type="outer"> <attribute name="opportunityid" /> <attribute name="customerid" /> <link-entity name="account" from="accountid" to="customerid" alias="opportunityaccount" link-type="outer" > <attribute name="accountid" /> <attribute name="territoryid" /> <filter type="and"> <condition attribute="accountid" operator="in" value="@account" /> </filter> </link-entity> <filter type="and"> <condition attribute="accountid" operator="in" value="@account" /> </filter> </link-entity> <link-entity name="contact" from="contactid" to="regardingobjectid" alias="cont" link-type="outer"> <attribute name="contactid" /> <attribute name="parentcustomerid" /> <link-entity name="account" from="accountid" to="parentcustomerid" alias="contactaccount" link-type="outer" > <attribute name="accountid" /> <attribute name="territoryid" /> <filter type="and"> <condition attribute="accountid" operator="in" value="@account" /> </filter> </link-entity> <filter type="and"> <condition attribute="accountid" operator="in" value="@account" /> </filter> </link-entity> <link-entity name="account" from="accountid" to="regardingobjectid" alias="acct" link-type="outer"> <attribute name="accountid" /> <attribute name="territoryid" /> <attribute name="name" /> <filter type="and"> <condition attribute="accountid" operator="in" value="@account" /> </filter> </link-entity> <link-entity name="appointment" from="activityid" to="activityid" alias="appt" link-type="outer"> <attribute name="activityid" /> <attribute name="new_appointmenttype" /> <attribute name="ownerid" /> <filter type="and"> <condition attribute="regardingobjectid" operator="not-null" /> <filter type="and"> <condition attribute="scheduledend" operator="on-or-after" value="@EventDateFrom"/> <condition attribute="scheduledend" operator="on-or-before" value="@EventDateTo"/> </filter> </filter> </link-entity> <link-entity name="phonecall" from="activityid" to="activityid" alias="phone" link-type="outer"> <attribute name="activityid" /> <attribute name="new_phonetype" /> <attribute name="ownerid" /> <filter type="and"> <condition attribute="regardingobjectid" operator="not-null" /> <filter type="and"> <condition attribute="scheduledend" operator="on-or-after" value="@EventDateFrom"/> <condition attribute="scheduledend" operator="on-or-before" value="@EventDateTo"/> </filter> </filter> </link-entity> </entity> </fetch>

あとは Business Intelligence Developer Studio を利用し上記 FetchXML を利用して、
実際のレポートを作成しました。

FetchXML のパフォーマンスについては、isquickfindfield オプションの利用も
検討してください。詳細はこちらの記事で紹介しています。

===========================================================================

まとめ

FetchXML は Microsoft Dynamics CRM 独自のクエリ言語であるため、慣れていない場合には
なかなか実際に取得したいデータを取得できるクエリを書けない場合があります。今後も
有用なサンプルがあれば随時紹介していきます。

- Dynamics CRM サポート 中村 憲一郎