Microsoft Dynamic CRM 自定义重复检测功能
2010-04-15 09:26
281 查看
表单中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;
}
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;
}
相关文章推荐
- Microsoft Dynamics CRM 2015 数据管理 之 重复检测 功能
- 检测重复文件功能实现
- Microsoft Dynamic CRM开发可配置接口(WCF/Webservice)
- AngularJS使用Filter自定义过滤器控制ng-repeat去除重复功能示例
- 检测重复文件功能实现(改进版本1)
- Microsoft Dynamics CRM 4.0 文章页面 添加自定义按钮
- Microsoft Dynamics CRM 4.0 的新增功能
- Microsoft Dynamics CRM 2015 新增功能 介绍 高级查找功能
- Dynamic CRM 2013学习笔记(四十三)流程6 - 自定义流程活动
- Microsoft Dynamics CRM 2013 --针对特定实体,取消保存功能(包含自动保存)
- Microsoft Dynamics CRM 2015 数据管理 功能 介绍
- Microsoft Dynamics CRM 2015 之安装SQL Server 2012过程中出现“启用windows功能NetFx3时出错
- Microsoft Dynamic CRM 2013安装
- 织梦57版本发布和修改检测文章标题重复的功能
- 使用代码克隆检测功能查找重复代码
- Dynamic CRM 2013学习笔记(三十七)自定义审批流7 - 初始化(整套审批流下载、安装)
- Dynamic CRM 2013学习笔记(十八)根据主表状态用JS控制子表自定义按钮
- Microsoft Dynamics CRM 4.0,IFD验证下,自定义aspx页面,如何获取当前的用户ID ?
- crm 重复检测
- CRM的客户数据模型:Microsoft Dynamic CRM 2011 (II)