利用微软自带的API方法将lookup字段查找视图进行过滤,
Xrm.Page.getControl(arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)
arg:需要过滤的lookup字段
viewId:自定义查找视图的GUID(随意写一个GUID就可以了)
entityName:实体名称
viewDisplayName:视图名称
fetchXml:fetchXml 查询
layoutXml:定义视图布局的 XML
isDefault:视图是否应该是默认视图
注:此方法不能用于"负责人"查找
实例如下:
const arg = "new_user_id"; //lookup字段
const viewId = "{33DC9B55-CC17-3F12-ASD6-F7533CC8B1B4}"; //视图ID
const entityName = "new_user"; //实体
const viewDisplayName = "自定义查找"; //视图名称
const isDefault = true //视图默认方式
const name = "上海"; //城市查询条件
//构造的FetchXML
const fetchXml = `<fetch version='1.0' output-format='xml-platform' mapping='logical'><entity name='new_user'><attribute name='new_name'/><attribute name='new_userid'/><link-entity name='new_city' from='new_user_id' to='new_userid'><filter type='and'><condition attribute='new_name' operator='eq' value='${name}'></condition></filter></link-entity></entity ></fetch >`
//构造的LayoutXML(视图布局)
const layoutXml = `<grid name='resultset' object='1' jump='${entityName}id' select='1' icon='1' preview='1'><row name='result' id='${entityName}id'><cell name='new_name' width='100'/></row></grid>`;
//构造lookup自定义查找视图
Xrm.Page.getControl(arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)