Microsoft Dynamic CRM 自定义重复检测功能

表单中Onsave中
var Attributes=new Array();
Attributes[0]="zz_accountid";
var Conditions=new Array();
Conditions[0]=new Array

("zz_accountid","Equal",crmForm.all.zz_accountid.DataValue[0].id.replace

("{","").replace("}",""));
Conditions[1]=new Array

("zz_zywqjid","Equal",crmForm.all.zz_zywqjid.DataValue[0].id.replace

("{","").replace("}",""));
Conditions[2]=new Array

("zz_productid","Equal",crmForm.all.zz_productid.DataValue[0].id.replace

("{","").replace("}",""));
Conditions[3]=new Array

("zz_systemuserid","Equal",crmForm.all.zz_systemuserid.DataValue

[0].id.replace("{","").replace("}",""));
var resultXml=MyRetrieveMultiple("zz_zlccx", Attributes, Conditions);
var results=resultXml.getElementsByTagName('BusinessEntity');
if(results.length>0)
{
alert("已经有相同的临床纯销了,不能再新建了!");
event.returnValue=false;
return false;
}

//根据条件取记录,支持多条件,多记录和取多字段
function MyRetrieveMultiple(EntityName, Attributes, Conditions) {
    var authenticationHeader = GenerateAuthenticationHeader();
    //            var authenticationHeader = "";
    var sAttributes;
    var sConditions;
    sAttributes = "";
    sConditions = "";
    for (var i = 0; i < Attributes.length; i++) {

        sAttributes += "<q1:Attribute>" + Attributes[i] + "</q1:Attribute>";
    }
    for (var i = 0; i < Conditions.length; i++) {

        var Con = Conditions[i];
        sConditions += "<q1:Condition>";
        sConditions += "<q1:AttributeName>" + Con[0] +

"</q1:AttributeName>";
        sConditions += "<q1:Operator>" + Con[1] + "</q1:Operator>";
        sConditions += "<q1:Values>";
        sConditions += "<q1:Value xsi:type='xsd:string'>" + Con[2] +

"</q1:Value>";
        sConditions += "</q1:Values>";
        sConditions += "</q1:Condition>";
    }
    // Prepare the SOAP message.
    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
             "<soap:Envelope

xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
             " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
             " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
             authenticationHeader +
             "<soap:Body>" +
             "<RetrieveMultiple

xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
             "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"

+
             " xsi:type='q1:QueryExpression'>" +
             "<q1:EntityName>" + EntityName + "</q1:EntityName>" +
             "<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
             "<q1:Attributes>" +
             sAttributes +
             "</q1:Attributes>" +
             "</q1:ColumnSet>" +
            "<q1:Distinct>false</q1:Distinct>" +
            "<q1:Criteria>" +
            "<q1:FilterOperator>And</q1:FilterOperator>" +
            "<q1:Conditions>" +
            sConditions +
            "</q1:Conditions>" +
            "</q1:Criteria>" +
            "</query>" +
            "</RetrieveMultiple>" +
            "</soap:Body>" +
            "</soap:Envelope>";
    // Prepare the xmlHttpObject and send the request.
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction",

"http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    var resultXml = xHReq.responseXML;
    return resultXml;
}

刘祖军
原文地址:https://www.cnblogs.com/liuzujun/p/1712333.html