Dynamics CRM2013 Lookup Filtering using addCustomFilter

dynamics crm中对lookup视图的过滤是一个很平常性的需求,在2011的时候都是用添加自定义视图的方式例如下面这段示例代码

<span style="font-size: 18px;">var pEntityName = "sc_stock";
    var pViewDisplayName = "符合条件库存";
    var </span><span style="font-size:18px;">pSotckControl</span><span style="font-size: 18px;">= Xrm.Page.getControl("new_stock");
     
    var pFetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
                    + "<entity name='sc_stock'><attribute name='sc_stockid'/>"
                    + "<attribute name='sc_stocksn'/><attribute name='createdon'/>"
                    + "<attribute name='sc_salebillamount'/><attribute name='sc_outputamount'/>"
                    + "<attribute name='sc_bizbookresidue'/><attribute name='sc_bizbookamount'/>"
                    + "<attribute name='sc_owner'/><attribute name='sc_storage'/>"
                    + "<attribute name='sc_stocktype'/>"
                    + "<attribute name='sc_uom'/>"
                    + "<attribute name='sc_tank'/>"
                    + "<attribute name='sc_product'/>"
                    + "<attribute name='sc_bizunit'/>"
                    + "<attribute name='sc_bizoperator'/>"
                    + "<attribute name='sc_purchase'/>"
                    + "<order attribute='sc_stocksn' descending='false'/>"
                    + "<filter type='and'>"
                    + "<condition attribute='sc_decreaseandoverflow' operator='eq' value='" + this.sc_isDecreaseandoverflow + "'/>"                    
                    + "</filter>"
                    + "</entity>"
                    + "</fetch>"

     var pLayoutXml = "<grid name='resultset' object='10122' jump='sc_stocksn' select='1' icon='1' preview='1'>"
                        + "<row name='result' id='sc_stockid'>"
                        + "<cell name='sc_stocksn' width='100'/><cell name='sc_purchase' width='100'/>"
                        + "<cell name='sc_bizunit' width='100'/><cell name='sc_bizoperator' width='100'/>"
                        + "<cell name='sc_product' width='100'/><cell name='sc_owner' width='100'/>"
                        + "<cell name='sc_storage' width='100'/><cell name='sc_tank' width='100'/>"
                        + "<cell name='sc_stocktype' width='100'/><cell name='sc_uom' width='100'/>"
                        + "<cell name='sc_bizbookamount' width='100'/><cell name='sc_bizbookresidue' width='100'/>"
                        + "<cell name='sc_outputamount' width='100'/><cell name='sc_salebillamount' width='100'/>"
                        + "<cell name='createdon' width='125'/>"
                        + "</row></grid>"
     var id = "{CFD4B604-1C6A-4E61-B057-BA07620C0D46}";         
     pSotckControl.addCustomView(id, pEntityName, pViewDisplayName, pFetchXml, pLayoutXml, false);
     pSotckControl.setDefaultView(id);</span>
要写一大堆的查询XML,显示XML很是繁琐

2013中加入了addCustomFilter这个API,

<span style="font-size:18px;">Xrm.Page.getControl("new_stock").addPreSearch(function () {
        var filter = "<filter type='and'>"
        + "<condition attribute='sc_decreaseandoverflow' operator='eq' value='" + this.sc_isDecreaseandoverflow + "'/>"
        + "</filter>";
        Xrm.Page.getControl("new_stock").addCustomFilter(filter);
    });</span>
代码极度简化,XML也只是用到了一个condition条件而已,只是对默认的视图添加了搜索过滤而不是添加新的自定义视图。

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/VicTang/p/4799578.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值