D365视图开发:用FetchXML筛选当前用户部门关联案例
问题分析与解决方案
原FetchXML存在两个核心问题:
- 错误关联了案例所有者(ownerid)的用户实体,而需求是匹配当前登录用户的部门,两者逻辑完全无关
- 筛选条件引用了所有者用户的部门名称,未关联当前登录用户的部门信息
修正后的FetchXML
直接通过$CurrentUser全局变量获取当前登录用户的部门名称,与案例的openedbydepartment文本字段匹配即可,无需多余的关联实体:
<fetch> <entity name="incident"> <attribute name="ticketnumber" /> <attribute name="title" /> <attribute name="department" /> <attribute name="prioritycode" /> <attribute name="caseorigincode" /> <attribute name="customerid" /> <attribute name="statuscode" /> <attribute name="ownerid" /> <attribute name="incidentid" /> <filter type="and"> <condition attribute="statecode" operator="eq" value="0" /> <!-- 匹配当前登录用户的部门名称与案例的openedbydepartment字段 --> <condition attribute="openedbydepartment" operator="eq" valueof="$CurrentUser.department.name" /> </filter> </entity> </fetch>
关键说明
$CurrentUser是Dynamics 365内置的全局变量,直接指向当前登录用户的systemuser记录$CurrentUser.department.name会自动获取当前用户关联部门的名称文本,与你存储在openedbydepartment的文本值直接匹配- 移除了不必要的
link-entity关联,简化查询逻辑的同时避免了无关数据干扰
内容的提问来源于stack exchange,提问作者Shivani
相关产品推荐
相关产品推荐

