如何使用Fetch查询不属于指定Queue或team的用户
结论
可以通过FetchXML实现该需求,你之前配置未得到预期结果的核心原因是:用户(systemuser)与团队(team)为多对多关联关系,直接对team实体设置「不等于指定团队」的筛选规则,无法匹配多对多关联的逻辑;而Queue是队列实体,和用户的团队隶属关系无直接关联,替换筛选对象后自然也无法得到正确结果。
正确实现逻辑
- 对用户与团队的多对多中间关联表
teammembership做左外连接,关联条件同时指定两个规则:- 关联
systemuser.systemuserid = teammembership.systemuserid - 指定关联的团队为你要排除的目标团队:
teammembership.teamid = 你要排除的目标团队GUID
- 关联
- 新增筛选条件:
teammembership.systemuserid为空,符合该条件的用户即为不属于目标团队的用户
FetchXML示例代码
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true"> <entity name="systemuser"> <attribute name="fullname" /> <attribute name="internalemailaddress" /> <attribute name="systemuserid" /> <order attribute="fullname" descending="false" /> <!-- 左外连接团队成员中间表,指定要排除的目标团队ID --> <link-entity name="teammembership" from="systemuserid" to="systemuserid" link-type="outer" alias="excluded_team"> <filter type="and"> <condition attribute="teamid" operator="eq" value="这里替换为你要排除的目标团队的GUID" /> </filter> </link-entity> <!-- 筛选未关联到目标团队的用户 --> <filter type="and"> <condition entityname="excluded_team" attribute="systemuserid" operator="null" /> <!-- 可按需新增其他筛选条件,比如仅展示启用的用户 --> <condition attribute="isdisabled" operator="eq" value="0" /> </filter> </entity> </fetch>
内容的提问来源于stack exchange,提问作者Damkulul
相关产品推荐
相关产品推荐

