关于Alexa CRM插件在WordPress中无法显示Dynamics CRM聚合结果的问题咨询
我目前正在使用WordPress的Alexa CRM插件连接Dynamics CRM,尝试获取以下聚合查询的结果:
[msdyncrm_twig] {% fetchxml collection="simpleagg" cache="PT30M" %} <fetch aggregate="true"> <entity name="account"> <attribute name="accountid" alias="AccountCount" aggregate="count" /> </entity> </fetch> {% endfetchxml %} {{simpleagg.results.entities[0].AccountCount}} [/msdyncrm_twig]
这段代码没有返回任何内容,但我用XrmToolBox测试完全相同的FetchXML查询时,得到了预期的结果。我已经尝试过{{simpleagg.results.entities[0].account}}、{{simpleagg.results.entities[0].accountid}}等写法,但都没用。另外,我正常处理视图是没有问题的,有没有人知道我哪里遗漏了?
编辑:我把{{simpleagg.results.entities[0].AccountCount}}移到...(内容未完成)
我之前处理过类似的插件问题,给你几个实用的排查思路:
先搞清楚返回结果的真实结构
别瞎猜字段名了,直接输出整个返回对象看看!如果插件支持Twig的dump函数,把代码改成这样:[msdyncrm_twig] {% fetchxml collection="simpleagg" cache="PT30M" %} <fetch aggregate="true"> <entity name="account"> <attribute name="accountid" alias="AccountCount" aggregate="count" /> </entity> </fetch> {% endfetchxml %} {{ dump(simpleagg.results) }} [/msdyncrm_twig]这样就能看到返回的所有数据结构,比如字段名是不是被转成了小写,或者聚合结果存在哪个节点里。
试试大小写不同的字段名
有些插件会自动把聚合别名转换成全小写,比如你的AccountCount可能变成了accountcount,可以试试{{simpleagg.results.entities[0].accountcount}},说不定就成了。检查插件对聚合查询的特殊处理
普通视图和聚合查询的返回结构可能不一样,有些插件会把聚合结果放在专门的节点里,而不是entities[0]里。通过上面的dump输出就能找到正确的路径。看看插件的调试日志
开启插件的调试模式(如果有的话),这样能看到插件向Dynamics CRM发送的请求和收到的响应,确认是不是插件没正确解析返回的聚合数据。
备注:内容来源于stack exchange,提问作者Cameron Jones

