FetchXML在XRM Tool Box正常,Power Pages门户关联实体过滤失效求助
排查方案与修复建议
1. 替换link-type="not all"为兼容写法
Power Pages调用的Dataverse Web API对not all这类link-type的支持存在差异,建议改用outer join + 反向过滤的写法实现相同逻辑:
- 将
link-type="not all"改为link-type="outer"并添加别名 - 在link-entity的filter中,用
or组合两个条件:关联记录不存在,或者关联的contact不等于目标ID
修改后的FetchXML代码:
var testFetchXML = ` <fetch version="1.0" mapping="logical" output-format="xml-platform" distinct="true"> <entity name="tgm_notification"> <attribute name="tgm_notificationid" /> <attribute name="tgm_title" /> <attribute name="tgm_message" /> <attribute name="tgm_type" /> <attribute name="tgm_targetaudience" /> <attribute name="tgm_targetaccount" /> <attribute name="tgm_targetrole" /> <attribute name="tgm_publishedfrom" /> <attribute name="tgm_publishedto" /> <attribute name="createdon" /> <order attribute="createdon" descending="true" /> <filter type="and"> <condition attribute="statecode" operator="eq" value="0" /> <link-entity name="tgm_notificationstatustracker" from="tgm_notification" to="tgm_notificationid" link-type="outer" alias="tracker"> <filter type="or"> <condition attribute="tgm_contact" operator="ne" value="67cf586a-afd9-eb11-bacb-000d3abc2473" uitype="contact" /> <condition attribute="tgm_notificationstatustrackerid" operator="null" /> </filter> </link-entity> </filter> </entity> </fetch>`;
2. 验证权限完整性
- 确认
tgm_notificationstatustracker表的权限不仅包含读取,还允许访问tgm_contact字段内容 - 检查Portal用户所属Web角色,是否对关联的
contact实体有至少读取权限(即使仅匹配ID,权限缺失也可能导致过滤失效)
3. 检查FetchXML编码结果
在浏览器控制台打印encodeURIComponent(testFetchXML)的结果,对比XRM Toolbox中可正常运行的原始XML,确认转义后的XML未丢失或篡改关键节点(如<link-entity>、<filter>标签)
4. 调试Web API请求
在浏览器开发者工具的Network面板中,查看实际发送的请求URL,复制完整的fetchXml参数值,粘贴到XRM Toolbox中重新测试,确认编码后的FetchXML仍能正常生效
内容的提问来源于stack exchange,提问作者Ayush Mishra
相关产品推荐
相关产品推荐

