Dynaimc CRM查找字段自定义过滤视图

打印 上一主题 下一主题

主题 915|帖子 915|积分 2745

实现方式参考官方文档提供的Xrm.Page.getControl(arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)参数的解释:viewId:具体的视图id 可通过视图编辑器窗体上方的网址中复制entityName:实体名viewDisplayName:视图名称,可自己编写一个名称fetchXml:过滤查询用的具体fetchXml语句,类似于编写sql,可以通过在线sql转fetchxml工具转换( http://www.sql2fetchxml.com/)layoutXml:定义视图布局的 XML,格式比较固定,以一个比较简单的为例:
  1. layoutXml = '<grid name="resultset" object="10057" jump="foton_sequenceno" select="1" icon="1" preview="1"><row name="result" id="foton_receiptid"><cell name="foton_sequenceno" width="150" /><cell name="createdon" width="150" /></row></grid>';
复制代码
注意:xml的连接符号如:''不要有空格中name可固定为resultset,也可以定义成实体名object为对应实体的ObjectTypeCode,数据库查询或者实体浏览器中查看select用0或1都可以 0和1对应是否可以在视图中进行查询icon和preview固定1中的name固定result即可,id为对应的实体主键为具体要显示的列配置,name为字段名,width为显示的宽度isDefault:视图是否应该是默认视图 默认设置为true即可 项目中的使用示例:1.给字段添加onchange事件
  1. 1 /** 2  * 选择产品代码后,根据产品资源与包装方式的关系过滤包装方式可选择的数据,添加自定义过滤视图 3  * @param {any} productFourthId  产品代码数据id 4  */ 5 function addPostingLookupFilterCustomView(productFourthId) { 6     if (productFourthId == null) { 7         return 8     } 9     let fetchXml = '';10     let layoutXml = '<grid name="resultset" object="10057" jump="foton_sequenceno" select="1" icon="1" preview="1"><row name="result" id="foton_receiptid"><cell name="foton_sequenceno" width="150" /><cell name="createdon" width="150" /></row></grid>';11     Xrm.Page.getControl("new_way_of_packaging").addCustomView("{DB40ABE7-FB8D-4E41-ACF8-7569ECEAB149}", "new_way_of_packaging", "包装方式过滤产品资源查询", fetchXml, layoutXml, true);12 }
复制代码
2.在页面加载时做判断显示视图 结合查找字段addPreSearch的方法
  1. 1 //窗体onload函数汇总调用方法 2  3 /** 4  *过滤源、目标经销商来款可选视图 5  * @param {any} type  1转出账户 2转入账户 6  */ 7 function preAccountToParagraphFilterLookup(type) { 8     if (!type) { 9         return10     }11     if (type == 1) {12         Xrm.Page.getControl("new_lkaccount").addPreSearch(function () {13             addPostingLookupFilterCustomView(type)14         })15     } else {16         Xrm.Page.getControl("new_targetlkaccount").addPreSearch(function () {17             addPostingLookupFilterCustomView(type)18         })19     }  20 }21 /**22  * 添加过滤源、目标经销商来款可选择的自定义视图23  * @param {any} type  1转出账户 2转入账户24  */25 function addPostingLookupFilterCustomView(type) {27     var fetchXml = '';28     let amountId = null29     if (type == 1) {30         amountId = Xrm.Page.getAttribute("new_amountid_from").getValue()31         amountId = amountId ? amountId[0].id : null32         if (amountId == null) {33             return34         }35     } else {36         amountId = Xrm.Page.getAttribute("new_amountid_to").getValue()37         amountId = amountId ? amountId[0].id : null38         if (amountId == null) {39             return40         }41     }42     fetchXml = '';43     var layoutXml = '<grid name="resultset" object="10057" jump="foton_sequenceno" select="1" icon="1" preview="1"><row name="result" id="foton_receiptid"><cell name="foton_sequenceno" width="150" /><cell name="createdon" width="150" /></row></grid>';44 45     if (type == 1) {46         Xrm.Page.getControl("new_lkaccount").addCustomView("{4F08B504-491C-473F-B215-FF99894870D9}", "new_lkaccount", "经销商来款过滤资金账户查询", fetchXml, layoutXml, true);47     } else {48         Xrm.Page.getControl("new_targetlkaccount").addCustomView("{4F08B504-491C-473F-B215-FF99894870D9}", "new_lkaccount", "经销商来款过滤资金账户查询", fetchXml, layoutXml, true);49     }  50 }
复制代码
 
 
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

麻花痒

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表