Dynamics Crm 365 JS实现Lookup字段的自定义过滤

条件覆盖:

1.实现方法很简单,在Form的OnLoad事件加上preFilterLookup

function preFilterLookup() {
       Xrm.Page.getControl("new_postingid").addPreSearch(function () {  // child field
           addPostingLookupFilter();
       });
  }

 

2.用addCustomFilter来控制

function addPostingLookupFilter() {
       var gl = Xrm.Page.getAttribute("new_special_gl_indicatorid").getValue(); // parent field
       var fetchXml = "<filter type='and'><condition attribute='new_special_gl_indicatorid' operator='eq' value='" + gl[0].id + "' /></filter>";
      Xrm.Page.getControl("new_postingid").addCustomFilter(fetchXml); // child field
  }

 

 

全部覆盖:在onload执行

let entityName = "account";
        let viewDisplayName = "可用客户";
        let lookupControl = Xrm.Page.getControl(attributeName);  //字段名
        if (lookupControl == null) {
            return;
        }
        let id = '{2443A0FF-7988-43BC-849B-156F9B93FAD7}';
 
        let fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"
            + "  <entity name='account'>"
            + "    <attribute name='accountnumber' />"
            + "    <attribute name='name' />"
            + "    <attribute name='accountid' />"
            + "    <link-entity name='scc_team_for_cust' from='scc_cust_id' to='accountid' link-type='outer' alias='stfc'></link-entity>";
           + "  </entity>"
            + "</fetch>";

        let layoutXml = "<grid name='resultset' object='10013' jump='name' select='1' icon='1' preview='1'><row name='result' id='accountid'><cell name='accountnumber' width='300' /><cell name='name' width='300' /></row></grid>";
        lookupControl.addCustomView(id, entityName, viewDisplayName, fetchXml, layoutXml, false);
        lookupControl.setDefaultView(id);

 

更具体的:https://www.cnblogs.com/fengwenit/p/4003496.html

 

posted @ 2022-03-11 09:37  溜溜球_小钢wan  阅读(373)  评论(0编辑  收藏  举报