在之前的文章中,我介绍了如何创建基于Fetch的报表,并使用数据预筛选功能。在这篇文章中,我们使用一个比较复杂的FetchXML来完成一个更有实际意义的报表。
在这个报表中,显示相关客户,客户的订单,以及订单的产品信息。报表使用了三个inner join,account inner join order inner join orderdetail inner join product。
(1) 利用CRM的高级查找创建FetchXML
下载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" /> <filter type="and"> <condition attribute="statuscode" operator="eq" value="1" /> </filter> <link-entity name="salesorder" from="customerid" to="accountid" alias="aa"> <filter type="and"> <condition attribute="statecode" operator="ne" value="2" /> </filter> <link-entity name="salesorderdetail" from="salesorderid" to="salesorderid" alias="ab"> <link-entity name="product" from="productid" to="productid" alias="ac"></link-entity> </link-entity> </link-entity> </entity> </fetch>
(2) 我们将它拷贝到报表中数据集的Query,并进行一些修改(添加我们需要的attribute)
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true"> <entity name="account"> <attribute name="name" /> <attribute name="accountid" /> <order attribute="name" descending="false" /> <filter type="and"> <condition attribute="statuscode" operator="eq" value="1" /> </filter> <link-entity name="salesorder" from="customerid" to="accountid" alias="aa"> <attribute name="ordernumber" /> <attribute name="name" /> <attribute name="totalamount" /> <filter type="and"> <condition attribute="statecode" operator="ne" value="2" /> </filter> <link-entity name="salesorderdetail" from="salesorderid" to="salesorderid" alias="ab"> <attribute name="quantity" /> <attribute name="priceperunit" /> <attribute name="baseamount" /> <link-entity name="product" from="productid" to="productid" alias="ac"> <attribute name="name" /> </link-entity> </link-entity> </link-entity> </entity> </fetch>
(3) 按照之前的文章介绍,使用数据预筛选功能。
添加一个CRM_FilteredAccount参数,使用以下的Query:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="account"><all-attributes /></entity></fetch>
(4) 修改数据集Query的Fetch XML:
对这一行修改: <entity name="account" enableprefiltering="1" prefilterparametername="CRM_FilteredAccount">
修改结果为:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true"> <entity name="account" enableprefiltering="1" prefilterparametername="CRM_FilteredAccount"> <attribute name="name" /> <attribute name="accountid" /> <order attribute="name" descending="false" /> <filter type="and"> <condition attribute="statuscode" operator="eq" value="1" /> </filter> <link-entity name="salesorder" from="customerid" to="accountid" alias="aa"> <attribute name="ordernumber" /> <attribute name="name" /> <attribute name="totalamount" /> <filter type="and"> <condition attribute="statecode" operator="ne" value="2" /> </filter> <link-entity name="salesorderdetail" from="salesorderid" to="salesorderid" alias="ab"> <attribute name="quantity" /> <attribute name="priceperunit" /> <attribute name="baseamount" /> <link-entity name="product" from="productid" to="productid" alias="ac"> <attribute name="name" /> </link-entity> </link-entity> </link-entity> </entity> </fetch>
(5) 在设计面板中添加Table:
(6) 到这一步报表就完成了。将报表上传到CRM中看一下结果: