zoukankan      html  css  js  c++  java
  • 微软Dynamics CRM 2013介绍系列之三十:筛选查找控件,so easy。

            查找控件增加了preSearch事件。它发生在查找控件显示对话框供用户查找记录之前,与其他事件不同的是,不能使用界面来设定这个事件发生时执行的代码。只有通过Xrm.Page.getControl(arg).addPreSearch(handler) 和 Xrm.Page.getControl(arg).removePreSearch(handler) 来为该事件增加或者清除执行的代码。这个方法大大简化筛选查找字段的步骤,在Dynamics CRM 2011中要做到这样需要很多步骤。下面的演示主要参考 http://www.magnetismsolutions.com/blog/nathaneccles/2013/09/30/crm-2013-javascript-lookup-filtering-using-addcustomfilter

          本演示的作用是根据 单行文本 字段的值来筛选 客户 这个查找字段的可选择值(可以供选择的客户要以 单行文本 字段的值开头),使用的代码如下:

        

    function OnLoadHandler() {
        Xrm.Page.getControl("new_account").addPreSearch(function () {
            addLookupFilter();
        });
    }
    
    function OnSingleLineTextChangeHandler() {
        Xrm.Page.getAttribute("new_account").setValue(null);
        Xrm.Page.getControl("new_account").addPreSearch(function () {
            addLookupFilter();
        });
    }
    
    function addLookupFilter() {
        var singleLineText = Xrm.Page.getAttribute("new_singlelinetext").getValue();
        var fetchXml = "";
        if (singleLineText != null) {
            fetchXml = "<filter type='and'><condition attribute='name' operator='like' value='" + singleLineText + "%' /></filter>";
        }
        else {
            fetchXml = "<filter type='and'><condition attribute='name' operator='null' /></filter>";
        }
        Xrm.Page.getControl("new_account").addCustomFilter(fetchXml);
    }

     

    将上面的代码作为web resource上传以后,窗体属性的OnLoad事件执行OnLoadHandler函数。字段 单行文本 的OnChange 事件执行函数 OnSingleLineTextChangeHandler 。

    新建一条记录,在我不输入 单行文本 字段的值时 客户字段没有值可以选择。就算我点击 查找更多记录 ,弹出窗口中也是没有值可以选择。
    那我切换视图呢,查找记录窗口查看的视图我从 客户查找视图 切换到 可用客户,可以看到还是没有值可以选择,所以这个 addPreSearch 会作用于所有可用的视图,不错!
    然后我在 单行文本 字段中输入了 测试,这时候 客户 这个查找字段自动做了筛选了。

     如果我点击 查找更多记录 这个链接,在出来的 查找记录 DIV层中切换试图也只有符合条件的记录能出来,可见筛选还是比较全面的。

    如果我把 单行文本 字段的值更改成A,再输入 客户 字段,可见也自动做了合适的筛选。
     
    如果是Dynamics 365 Customer Engagement V9或者更高版本的话,写法稍有变化,我这里记录下:
    LY.DemoForm = {
        onLoad: function (executionContext) {
            var formContext = executionContext.getFormContext();
            formContext.getControl("ly_lookupfieldname").addPreSearch(LY.DemoForm.parentPreSearch);
        },
        parentPreSearch: function (executionContext) {
            var formContext = executionContext.getFormContext();
            var parentId = formContext.getAttribute("lvo_parentid").getValue();
            var presearchFilter = "";
            if (parentCase) {
                presearchFilter = "<filter type='and'><condition attribute='ly_parentid' operator='eq' value='" + parentId[0].id + "'/>";
                presearchFilter += "<condition attribute='ly_customerfield' operator='eq' value='测试条件'/></filter>";
                formContext.getControl("ly_lookupfieldname").addCustomFilter(presearchFilter);
            }
            else {
                presearchFilter = "<filter type='and'><condition attribute='ly_demoid' operator='eq' value='00000000-0000-0000-0000-000000000000' /></filter>";
            }
            formContext.getControl("ly_lookupfieldname").addCustomFilter(presearchFilter);
        }
    }
     
     
  • 相关阅读:
    UVA 818 Cutting Chains 切断圆环链 (暴力dfs)
    UVA 211 The Domino Effect 多米诺效应 (回溯)
    UVA225 Golygons 黄金图形(dfs+回溯)
    UVA208 Firetruck 消防车(并查集,dfs)
    UVA11212 EditingaBook ( IDA*搜索)
    UVA 140 Brandwidth 带宽 (dfs回溯)
    uva 1601 poj 3523 Morning after holloween 万圣节后的早晨 (经典搜索,双向bfs+预处理优化+状态压缩位运算)
    UVA10410 TreeReconstruction 树重建 (dfs,bfs序的一些性质,以及用栈处理递归 )
    cdoj 414 八数码 (双向bfs+康拓展开,A*)
    UVA 246 10-20-30 10-20-30游戏 模拟+STL双端队列deque
  • 原文地址:https://www.cnblogs.com/luoyong0201/p/Dynamics_CRM_2013_New_Feature_addPreSearch.html
Copyright © 2011-2022 走看看