web方式AJAX调用



var id =crmForm.all.new_productpricelevel_kz.DataValue[0].id
var nsrsbh =crmForm.all.new_name.DataValue;
//得到产品代码
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\">" + 
GenerateAuthenticationHeader() + 
"  <soap:Body>" + 
"    <Retrieve xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
"      <entityName>new_productpricelevel_kz</entityName>" + 
"      <id>"+id+"</id>" + 
"      <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:AllColumns\" />" + 
"    </Retrieve>" + 
"  </soap:Body>" + 
"</soap:Envelope>" + 
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;

var cpdm =resultXml.getElementsByTagName("q1:new_cpxmdm")[0].childNodes[0].nodeValue;


// 得到 用户ID
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\">" + 
GenerateAuthenticationHeader() + 
"  <soap:Body>" + 
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
"      <Request xsi:type=\"WhoAmIRequest\" />" + 
"    </Execute>" + 
"  </soap:Body>" + 
"</soap:Envelope>" + 
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;

var userID=resultXml.getElementsByTagName("UserId")[0].childNodes[0].nodeValue;

 //得到部门ID

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\">" + 
GenerateAuthenticationHeader() + 
"  <soap:Body>" + 
"    <Retrieve xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
"      <entityName>systemuser</entityName>" + 
"      <id>"+userID+"</id>" + 
"      <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:AllColumns\" />" + 
"    </Retrieve>" + 
"  </soap:Body>" + 
"</soap:Envelope>" + 
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;

var bmid=resultXml.getElementsByTagName("q1:businessunitid")[0].childNodes[0].nodeValue

//得到部门网站
 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\">" + 
GenerateAuthenticationHeader() +
"  <soap:Body>" + 
"    <Retrieve xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
"      <entityName>businessunit</entityName>" + 
"      <id>"+bmid+"</id>" + 
"      <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:AllColumns\" />" + 
"    </Retrieve>" + 
"  </soap:Body>" + 
"</soap:Envelope>" + 
"";



var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;
webUrl =resultXml.getElementsByTagName("q1:websiteurl")[0].childNodes[0].nodeValue;
var url=  webUrl .replace(";", "?");
url +="<?xml version='1.0' encoding='UTF-8'?><MSG><REQHEAD><YWLX_DM>EDES.SERVICE.QUERY.QUERY_JFXX_BY_FWCP_AND_NSRSBH</YWLX_DM><TOKEN>wEPDwUJOTA5MDI0MzY0D2QWAmYPZBYCAgEPZBYEAgEPZBYCAgEPFQEUL0luY2x1ZGUvamF2YXNjcmlwdC9kAgMPZBYMAgEPZBYUZg8PFgo</TOKEN></REQHEAD><REQBODY><NSRSBH>"+nsrsbh+"</NSRSBH><FWCP_DM>"+cpdm+"</FWCP_DM></REQBODY></MSG>";


xmlHttpRequest.Open("GET", url,false);

xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

xmlHttpRequest.send(null);

var resultXml = xmlHttpRequest.responseText;

  var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(resultXml );
var begindatevalue= xmlDoc.getElementsByTagName("QSRQ")[0].childNodes[0].nodeValue;
begindatevalue =begindatevalue.replace(/-/g, '/ '); 

var enddatevalue= xmlDoc.getElementsByTagName("JZRQ")[0].childNodes[0].nodeValue;
enddatevalue=enddatevalue.replace(/-/g, '/ '); 
var fwbh =xmlDoc.getElementsByTagName("FWBH")[0].childNodes[0].nodeValue;

var cpmc =xmlDoc.getElementsByTagName("FWCP_MC")[0].childNodes[0].nodeValue;
alert("办理产品:"+cpmc+"  起始时间:"+begindatevalue+"  截止时间:"+enddatevalue+"");

crmForm.all.new_fwbh.DataValue=fwbh;
crmForm.all.new_yxqq.DataValue = new Date( begindatevalue);
crmForm.all.new_yxqz.DataValue= new Date( enddatevalue);

posted on 2010-07-31 23:52  HelloHongfu  阅读(358)  评论(0编辑  收藏  举报

导航