最近有一个做图表的需求,具体如下:
1)以商机拥有者的团队为列,统计每个团队的商机数目
2)再统计各类型商机的数目
刚接触时以为就是个普通的图表,一个图例条目(序列)是团队,另一个是商机类型(是自定义的OptionSet)。导出图表在FetchXml中使用Link-entity轻松列出各团队。但是导入这个图表时就发现有问题了,在所有的商机中,商机类型这个OptionSet有1个类型完全没有出现过,有个团队也没有任何商机。而客户希望图表中能显示所有的类型,所有的团队。因为在所有数据中都没有出现过的选项 ,无论怎么用outer join都是无法显示出来的。
这个问题纠结了半天,最后想出个比较傻的方法。那就是为没有出现过的类型自己创建一个Dummy Record,创建人为testAccount,把testAccount放在没数据的那个团队中。在FetchXml中Filter掉这个DummyRecord,outer join就能把这类型显示出来了。
建这个图表的实际操作如下:
1)为没有出现过的Option创建几个假的数据
2)创建1个图表,legend选商机名字count:All,Categories选owner,再添加Opp Type,
3)导出图表,修改FetchXml如下
<fetchmapping="logical" aggregate="true">
<entity name="opportunity">
<attribute groupby="true"alias="_CRMAutoGen_groupby_column_Num_0" name="new_opptype"/>
//取得团队
<link-entity name="systemuser"from="systemuserid" to="owninguser"alias="aa">
<link-entity name="teammembership"from="systemuserid" to="systemuserid" visible="false"intersect="true">
<link-entityname="team" from="teamid" to="teamid"alias="ab">
<attribute name="name" alias="groupby_team"groupby="true"/>
//filter出来需要显示的团队,这里省略
</link-entity>
</link-entity>
</link-entity>
//导出所有的Option
<link-entity name="opportunity"from="opportunityid" to="opportunityid"link-type="outer">
<attribute alias="arregrateby_name"name="name" aggregate="countcolumn" />
//滤掉dummy record
<filter>
<condition attribute="ownerid" operator="ne"uiname="testAccount" uitype="systemuser"value="{02F0EC01-F200-E311-9F79-E4115BBAA0B6}"/>
</filter>
</link-entity>
</entity>
</fetch>
4)修改fetchcollection下面的categorycollection
<categorycollection>
<categoryalias="groupby_team">
<measurecollection>
<measurealias="arregrateby_name" />
</measurecollection>
</category>
</categorycollection>
5)调整一些个人喜欢的参数
6)保存并导入
刷新一下图表,就看到DP可以正常显示出来了,统计的商机数量为0
谢谢阅读!
Jake Zhong