c#教程
https://www.jxasp.com/blog
实现方式参考官方文档提供的Xrm.Page.getControl(arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)
参数的解释:
viewId:具体的视图id 可通过视图编辑器窗体上方的网址中复制
entityName:实体名
viewDisplayName:视图名称,可自己编写一个名称
fetchXml:过滤查询用的具体fetchXml语句,类似于编写sql,可以通过在线sql转fetchxml工具转换( SQL2FetchXML - Free online converter that converts SQL script to FetchXML - Powered by KingswaySoft)
layoutXml:定义视图布局的 XML,格式比较固定,以一个比较简单的为例:
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的连接符号如:'<''>'不要有空格
<grid>中name可固定为resultset,也可以定义成实体名
object为对应实体的ObjectTypeCode,数据库查询或者实体浏览器中查看
select用0或1都可以 0和1对应是否可以在视图中进行查询
icon和preview固定1
<row>中的name固定result即可,id为对应的实体主键
<cell>为具体要显示的列配置,name为字段名,width为显示的宽度
isDefault:视图是否应该是默认视图 默认设置为true即可
项目中的使用示例:
1.给字段添加onchange事件

1 /**
2 * 选择产品代码后,根据产品资源与包装方式的关系过滤包装方式可选择的数据,添加自定义过滤视图
3 * @param {any} productFourthId 产品代码数据id
4 */
5 function addPostingLookupFilterCustomView(productFourthId) {
6 if (productFourthId == null) {
7 return
8 }
9 let fetchXml = '<fetch version="1.0" mapping="logical"><entity name="new_way_of_packaging"><attribute name="new_way_of_packagingid" /><attribute name="new_name" /><attribute name="new_cost" /><attribute name="createdon" /><link-entity name="new_product_packaging_relationship" from="new_way_of_packagingid" to="new_way_of_packagingid" alias="ship" link-type="inner"><filter type="and"><condition attribute="new_product_fourthid" operator="eq" value="' + commonUtil.delBrackets(productFourthId) + '" /></filter></link-entity></entity></fetch>';
10 let layoutXml = '<grid name="" object="10047" jump="new_name" select="1" icon="1" preview="0"><row name="new_way_of_packaging" id="new_way_of_packagingid"><cell name="new_name" width="300" /><cell name="new_cost" width="https://cdn.jxasp.com:9143/image/200" /><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 //窗体onload函数汇总调用方法
2
3 /**
4 *过滤源、目标经销商来款可选视图
5 * @param {any} type 1转出账户 2转入账户
6 */
7 function preAccountToParagraphFilterLookup(type) {
8 if (!type) {
9 return
10 }
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 = null
29 if (type == 1) {
30 amountId = Xrm.Page.getAttribute("new_amountid_from").getValue()
31 amountId = amountId ? amountId[0].id : null
32 if (amountId == null) {
33 return
34 }
35 } else {
36 amountId = Xrm.Page.getAttribute("new_amountid_to").getValue()
37 amountId = amountId ? amountId[0].id : null
38 if (amountId == null) {
39 return
40 }
41 }
42 fetchXml = '<fetch version="1.0" mapping="logical"><entity name="new_lkaccount"><attribute name="new_lkaccountid" /><attribute name="new_name" /><attribute name="createdon" /><filter type="and"><condition attribute="new_approvalstatus" operator="eq" value="40" /><filter type="or"><condition attribute="new_amountid_capital" operator="eq" value="' + commonUtil.delBrackets(amountId) + '" /><condition attribute="new_amountid_parts" operator="eq" value="' + commonUtil.delBrackets(amountId) + '" /></filter></filter></entity></fetch>';
43 var layoutXml = '<grid name="" object="10174" jump="new_name" select="1" icon="1" preview="0"><row name="new_lkaccount" id="new_lkaccountid"><cell name="new_name" width="300" /><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 }



![战神引擎传奇手游【黯晶灭世[白猪3.1]】最新整理Win系特色服务端+安卓苹果双端+GM授权后台+详细搭建教程](https://cdn.jxasp.com:9143/image/20251028/0F2E0E55BA6157D5F76B8125D0A511AC.jpg)
















