自定义视图的作用很多,最常用的就是给页面上的lookup字段进行筛选
Xrm.Page.getControl("fieldid").addPreSearch(function () {
var filter = "<filter type='and'>"
+ "<condition attribute='xxx' operator='eq' value='" + xxx + "'/>"
+ "</filter>";
Xrm.Page.getControl("fieldid").addCustomFilter(filter);
});
但是在CustomFilter
涉及到多个entity,需求很复杂的时候上面这种方式就有点力不从心了
那么还有一种原始的xml的方式可供使用,虽然复杂但是功能强大:
-
首先我们去系统高级查找页面创建要用的查找试图
-
点击
下载Fetch XML
按钮就可以下载到xml格式的代码 -
在js代码中使用这个xml
var pFetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
+ "<entity name='syzz_entity1'><attribute name='syzz_deliverynoteid'/>"
+ "<attribute name='syzz_name'/><attribute name='createdon'/>"
+ "<attribute name='syzz_orderid'/>"
+ "<order attribute='createdon' descending='false'/>"
+ "<filter type='and'>"
+ "<condition attribute='syzz_site' operator='eq' value='" + currentBaseGuid + "' />"
+ "</filter>"
+ "<link-entity name='syzz_order' from='syzz_orderid' to='syzz_orderid' alias='aa'>"
+ "<filter type='and'>"
+ "<condition attribute='syzz_ordertype' operator='ne' value='2' />"
+ "</filter>"
+ "</link-entity>"
+ "</entity>"
+ "</fetch>"
//这里是布局代码可以套用
var pLayoutXml = "<grid name='resultset' object='10122' jump='syzz_entity1sn' select='1' icon='1' preview='1'>"
+ "<row name='result' id='syzz_deliverynoteid'>"
+ "<cell name='syzz_name' width='100'/><cell name='createdon' width='100'/>"
+ "</row></grid>"
var id = "{CFD4B604-1C6A-4E61-B057-BA07620C0D46}";
Xrm.Page.getControl("syzz_delierynotedetail").addCustomView(id, "syzz_entity1", "我的自定义视图", pFetchXml, pLayoutXml, true);//最后一个bool参数用来设定是否将这个试图设置为默认试图