• MS CRM 2011 中JS控制Lookup筛选


     
    function addCityCustomView(viewId, entityName, viewDisplayName) {
    var oProvince = Xrm.Page.data.entity.attributes.get("sinochem_province");
    var parentID = oProvince.getValue()[0].id;
    if (parentID != "") {
    var oCity = Xrm.Page.data.entity.attributes.get("sinochem_city");
    var fetchXml = " <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
    "<entity name='sinochem_nationinformation'>" +
    "<order attribute='sinochem_name' descending='false' />" +
    "<filter type='and'>" +
    "<condition attribute='sinochem_parent' operator='eq' value='" + parentID + "' />" +
    "<condition attribute='sinochem_level' operator='eq' value='3' />" +
    "</filter>" +
    "<attribute name='sinochem_name' />" +
    "<attribute name='sinochem_nationinformationid' />" +
    "</entity>" +
    "</fetch>"
    var layoutXml = "<grid name='resultset' object='10065' jump='sinochem_name' select='1' preview='1' icon='1'>" +
    "<row name='result' id='sinochem_nationinformationid'>" +
    "<cell name='sinochem_name' width='150' />" +
    "</row>" +
    "</grid>"

    var lookupControls = Xrm.Page.ui.controls.get("sinochem_city");
    processLookup(lookupControls, viewId, entityName, viewDisplayName, fetchXml, layoutXml);

    }
    else {
    Xrm.Page.getControl(
    "sinochem_city").setDisabled(true); // Disabled
    }

    }

    function processLookup(lookupControl, viewId, entityName, viewDisplayName, fetchXml, layoutXml) {
    // Get the default view of the lookup before it is modified
    var currentDefaultViewId = lookupControl.getDefaultView();
    var oReq = getXMLHttpRequest();
    if (oReq != null) {
    var url = "http://" + location.host + "/" + Xrm.Page.context.getOrgUniqueName() + "/XRMServices/2011/OrganizationData.svc/SavedQuerySet(guid'" + currentDefaultViewId + "')";
    oReq.url
    = url;
    oReq.open(
    "GET", url, true);
    oReq.onreadystatechange
    = function () {
    changeLookupDefaultView(oReq, lookupControl, viewId, entityName, viewDisplayName, fetchXml, layoutXml);
    };

    oReq.send();
    }

    }

    function isLookup(control, index) {
    return control.getControlType() == "lookup";
    }

    function getXMLHttpRequest() {
    if (window.XMLHttpRequest) {
    return new window.XMLHttpRequest;
    }
    else {
    try
    {
    return new ActiveXObject("MSXML2.XMLHTTP.3.0"); }
    catch (ex) {
    return null;
    }
    }
    }

    function changeLookupDefaultView(oReq, lookupControl, viewId, entityName, viewDisplayName, fetchXml, layoutXml) {
    if (oReq.readyState == 4) {
    if (oReq.status == 200) {
    xmlDoc
    = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async
    = false;
    xmlDoc.loadXML(oReq.responseText);
    var returnedTypeCodeNode = xmlDoc.selectSingleNode("//d:ReturnedTypeCode");
    if (returnedTypeCodeNode) {
    var entityName = returnedTypeCodeNode.text;
    lookupControl.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml,
    false);
    lookupControl.setDefaultView(viewId);
    }
    }
    }
    }

      

  • 相关阅读:
    【Android UI设计与开发】第17期:滑动菜单栏(二)开源项目SlidingMenu的示例
    [Usaco2008 Dec]Patting Heads
    Hibernate(六)——多对多关联映射
    2017第2周一小程序
    2017第一周日
    2017第一周六
    无论你如何努力,总会有人讨厌你
    word使用技巧-批量删除图片技巧
    Web跨域问题总结
    JAVA语言的本质优势
  • 原文地址:https://www.cnblogs.com/Republic/p/2155083.html
Copyright © 2020-2023  润新知