MSCRM2011 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);
            }
        }
    }
}

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值