首页 新闻 会员 周边 捐助

求教指点CRM表单内编程

0
悬赏园豆:10 [待解决问题]

您好,麻烦博友看一下下面的CRM表单内编程的内容是否可以优化。

我的问题是4个试剂的可以用一个什么综合写到一起吗?

if(crmForm.ObjectId == null)
{

//试剂1.................................................................................lookup 筛选
var field = crmForm.all.new_nameid1;
    var stauls="2";
    var name="λ-Hind III";
     // Ensure that search box is not visible in a lookup dialog
    field.lookupbrowse = 1;
  // Pass fetch xml through search value parameter
    field.AddParam("search",
     "<fetch mapping='logical'><entity name='new_reagent'>"
    + "<filter><condition attribute='new_stauls' operator='eq' value='"
    + stauls
    + "' /><condition attribute='new_name' operator='eq' value='"
    + name
    + "' /></filter></entity></fetch>");

//................................................................lookup赋初值
// Prepare variables to fetch accounts.
var fetchMapping = "logical";
var entityName = "new_reagent";
var firstColumn = "new_reagentid";
var secondColumn = "new_name";
var linkEntity = "systemuser";
var linkEntityTo ="owninguser";
var filterType = "and";
var conditionAttribute1 = "new_name";
var operator1 = "eq";
var value1 = "λ-Hind III";
var conditionAttribute2 = "new_stauls";
var operator2= "eq";
var value2 = "2";
var authenticationHeader = GenerateAuthenticationHeader();

// 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>"+
"<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<fetchXml>&lt;fetch mapping='"+fetchMapping+"'&gt;"+
"&lt;entity name='"+entityName+"'&gt;"+
"&lt;attribute name='"+firstColumn+"'/&gt;"+
"&lt;attribute name='"+secondColumn+"'/&gt;"+
//"&lt;link-entity name='"+linkEntity+"' to='"+linkEntityTo+"'&gt;"+
//"&lt;filter type='"+filterType+"'&gt;"+
"&lt;filter&gt;"+
"&lt;condition attribute='"+conditionAttribute1+"'"+
" operator='"+operator1+"' value='"+value1+"'/&gt;"+
"&lt;condition attribute='"+conditionAttribute2+"'"+
" operator='"+operator2+"' value='"+value2+"'/&gt;"+
"&lt;/filter&gt;"+
//"&lt;/link-entity&gt;"+
"&lt;/entity&gt;"+
"&lt;/fetch&gt;</fetchXml>"+
"</Fetch>"+
"</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/Fetch");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
 var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
 alert(msg);
}
// Process and display the results.
else
{

// Capture the result and UnEncode it.
var resultSet = new String();
resultSet = resultXml.text;
resultSet.replace('&lt;','<');
resultSet.replace('&gt;','>');

// Create an XML document that you can parse.
   var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
   oXmlDoc.async = false;
// Load the XML document that has the UnEncoded results.
   oXmlDoc.loadXML(resultSet);
// Display the results.
   var results = oXmlDoc.getElementsByTagName('result');

        for (i=0;i < results.length;i++)
    {
     var idValue = results[i].selectSingleNode('./new_reagentid').nodeTypedValue;
     var name = results[i].selectSingleNode('./new_name').nodeTypedValue;
    }

var start_id= results[0].selectSingleNode('./new_reagentid').nodeTypedValue;
var start_name=results[0].selectSingleNode('./new_name').nodeTypedValue;
/*if(results.length>1)
{
alert('试剂λ-Hind III,不惟一,请选择!');
}*/
    //Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
   lookupItem.id = start_id;
   lookupItem.typename = 'new_reagent';
   lookupItem.name = start_name;
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.new_nameid1.DataValue = lookupData;
}

//.....................................................................retrieve和试剂有关的信息
// Prepare variables for a contact to retrieve.
var new_reagentid = start_id;
var authenticationHeader = GenerateAuthenticationHeader();

// 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>"+
"<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<entityName>new_reagent</entityName>"+
"<id>"+new_reagentid+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>new_number</q1:Attribute>"+
"<q1:Attribute>new_unites</q1:Attribute>"+
"<q1:Attribute>new_uniteprice</q1:Attribute>"+
"</q1:Attributes>"+
"</columnSet>"+
"</Retrieve>"+
"</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/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
var number=resultXml.selectSingleNode("//q1:new_number").nodeTypedValue;
crmForm.all.new_number1.DataValue=number;
var unites=resultXml.selectSingleNode("//q1:new_unites").nodeTypedValue;
crmForm.all.new_unite1.DataValue=unites;
var uniteprice=resultXml.selectSingleNode("//q1:new_uniteprice").nodeTypedValue;
crmForm.all.new_uniteprice1.DataValue=Number(uniteprice);
//试剂2.................................................................................lookup 筛选
var field = crmForm.all.new_nameid2;
    var stauls="2";
    var name="λ-Hind III";
     // Ensure that search box is not visible in a lookup dialog
    field.lookupbrowse = 1;
  // Pass fetch xml through search value parameter
    field.AddParam("search",
     "<fetch mapping='logical'><entity name='new_reagent'>"
    + "<filter><condition attribute='new_stauls' operator='eq' value='"
    + stauls
    + "' /><condition attribute='new_name' operator='eq' value='"
    + name
    + "' /></filter></entity></fetch>");

//................................................................lookup赋初值
// Prepare variables to fetch accounts.
var fetchMapping = "logical";
var entityName = "new_reagent";
var firstColumn = "new_reagentid";
var secondColumn = "new_name";
var linkEntity = "systemuser";
var linkEntityTo ="owninguser";
var filterType = "and";
var conditionAttribute1 = "new_name";
var operator1 = "eq";
var value1 = "λ-Hind III";
var conditionAttribute2 = "new_stauls";
var operator2= "eq";
var value2 = "2";
var authenticationHeader = GenerateAuthenticationHeader();
// 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>"+
"<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<fetchXml>&lt;fetch mapping='"+fetchMapping+"'&gt;"+
"&lt;entity name='"+entityName+"'&gt;"+
"&lt;attribute name='"+firstColumn+"'/&gt;"+
"&lt;attribute name='"+secondColumn+"'/&gt;"+
//"&lt;link-entity name='"+linkEntity+"' to='"+linkEntityTo+"'&gt;"+
//"&lt;filter type='"+filterType+"'&gt;"+
"&lt;filter&gt;"+
"&lt;condition attribute='"+conditionAttribute1+"'"+
" operator='"+operator1+"' value='"+value1+"'/&gt;"+
"&lt;condition attribute='"+conditionAttribute2+"'"+
" operator='"+operator2+"' value='"+value2+"'/&gt;"+
"&lt;/filter&gt;"+
//"&lt;/link-entity&gt;"+
"&lt;/entity&gt;"+
"&lt;/fetch&gt;</fetchXml>"+
"</Fetch>"+
"</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/Fetch");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
 var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
 alert(msg);
}
// Process and display the results.
else
{

// Capture the result and UnEncode it.
var resultSet = new String();
resultSet = resultXml.text;
resultSet.replace('&lt;','<');
resultSet.replace('&gt;','>');

// Create an XML document that you can parse.
   var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
   oXmlDoc.async = false;
// Load the XML document that has the UnEncoded results.
   oXmlDoc.loadXML(resultSet);
// Display the results.
   var results = oXmlDoc.getElementsByTagName('result');

        for (i=0;i < results.length;i++)
    {
     var idValue = results[i].selectSingleNode('./new_reagentid').nodeTypedValue;
     var name = results[i].selectSingleNode('./new_name').nodeTypedValue;
    }

var start_id= results[0].selectSingleNode('./new_reagentid').nodeTypedValue;
var start_name=results[0].selectSingleNode('./new_name').nodeTypedValue;
/*if(results.length>1)
{
alert('λ-Hind III,不惟一,请选择!');
}*/
    //Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
   lookupItem.id = start_id;
   lookupItem.typename = 'new_reagent';
   lookupItem.name = start_name;
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.new_nameid2.DataValue = lookupData;
}
//.....................................................................retrieve和试剂有关的信息
// Prepare variables for a contact to retrieve.
var new_reagentid = start_id;
var authenticationHeader = GenerateAuthenticationHeader();

// 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>"+
"<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<entityName>new_reagent</entityName>"+
"<id>"+new_reagentid+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>new_number</q1:Attribute>"+
"<q1:Attribute>new_unites</q1:Attribute>"+
"<q1:Attribute>new_uniteprice</q1:Attribute>"+
"</q1:Attributes>"+
"</columnSet>"+
"</Retrieve>"+
"</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/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
var number=resultXml.selectSingleNode("//q1:new_number").nodeTypedValue;
crmForm.all.new_number2.DataValue=number;
var unites=resultXml.selectSingleNode("//q1:new_unites").nodeTypedValue;
crmForm.all.new_unite2.DataValue=unites;
var uniteprice=resultXml.selectSingleNode("//q1:new_uniteprice").nodeTypedValue;
crmForm.all.new_uniteprice2.DataValue=Number(uniteprice);
//试剂3.................................................................................lookup 筛选
var field = crmForm.all.new_nameid3;
    var stauls="2";
    var name="10ul普通枪头";
     // Ensure that search box is not visible in a lookup dialog
    field.lookupbrowse = 1;
  // Pass fetch xml through search value parameter
    field.AddParam("search",
     "<fetch mapping='logical'><entity name='new_reagent'>"
    + "<filter><condition attribute='new_stauls' operator='eq' value='"
    + stauls
    + "' /><condition attribute='new_name' operator='eq' value='"
    + name
    + "' /></filter></entity></fetch>");

//................................................................lookup赋初值
// Prepare variables to fetch accounts.
var fetchMapping = "logical";
var entityName = "new_reagent";
var firstColumn = "new_reagentid";
var secondColumn = "new_name";
var linkEntity = "systemuser";
var linkEntityTo ="owninguser";
var filterType = "and";
var conditionAttribute1 = "new_name";
var operator1 = "eq";
var value1 = "10ul普通枪头";
var conditionAttribute2 = "new_stauls";
var operator2= "eq";
var value2 = "2";
var authenticationHeader = GenerateAuthenticationHeader();

// 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>"+
"<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<fetchXml>&lt;fetch mapping='"+fetchMapping+"'&gt;"+
"&lt;entity name='"+entityName+"'&gt;"+
"&lt;attribute name='"+firstColumn+"'/&gt;"+
"&lt;attribute name='"+secondColumn+"'/&gt;"+
//"&lt;link-entity name='"+linkEntity+"' to='"+linkEntityTo+"'&gt;"+
//"&lt;filter type='"+filterType+"'&gt;"+
"&lt;filter&gt;"+
"&lt;condition attribute='"+conditionAttribute1+"'"+
" operator='"+operator1+"' value='"+value1+"'/&gt;"+
"&lt;condition attribute='"+conditionAttribute2+"'"+
" operator='"+operator2+"' value='"+value2+"'/&gt;"+
"&lt;/filter&gt;"+
//"&lt;/link-entity&gt;"+
"&lt;/entity&gt;"+
"&lt;/fetch&gt;</fetchXml>"+
"</Fetch>"+
"</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/Fetch");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
 var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
 alert(msg);
}
// Process and display the results.
else
{

// Capture the result and UnEncode it.
var resultSet = new String();
resultSet = resultXml.text;
resultSet.replace('&lt;','<');
resultSet.replace('&gt;','>');

// Create an XML document that you can parse.
   var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
   oXmlDoc.async = false;
// Load the XML document that has the UnEncoded results.
   oXmlDoc.loadXML(resultSet);
// Display the results.
   var results = oXmlDoc.getElementsByTagName('result');

        for (i=0;i < results.length;i++)
    {
     var idValue = results[i].selectSingleNode('./new_reagentid').nodeTypedValue;
     var name = results[i].selectSingleNode('./new_name').nodeTypedValue;
    }

var start_id= results[0].selectSingleNode('./new_reagentid').nodeTypedValue;
var start_name=results[0].selectSingleNode('./new_name').nodeTypedValue;
if(results.length>1)
{
alert('10ul普通枪头,不惟一,请选择!');
}
    //Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
   lookupItem.id = start_id;
   lookupItem.typename = 'new_reagent';
   lookupItem.name = start_name;
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.new_nameid3.DataValue = lookupData;
}

//.....................................................................retrieve和试剂有关的信息
// Prepare variables for a contact to retrieve.
var new_reagentid = start_id;
var authenticationHeader = GenerateAuthenticationHeader();

// 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>"+
"<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<entityName>new_reagent</entityName>"+
"<id>"+new_reagentid+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>new_number</q1:Attribute>"+
"<q1:Attribute>new_unites</q1:Attribute>"+
"<q1:Attribute>new_uniteprice</q1:Attribute>"+
"</q1:Attributes>"+
"</columnSet>"+
"</Retrieve>"+
"</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/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
var number=resultXml.selectSingleNode("//q1:new_number").nodeTypedValue;
crmForm.all.new_number3.DataValue=number;
var unites=resultXml.selectSingleNode("//q1:new_unites").nodeTypedValue;
crmForm.all.new_unite3.DataValue=unites;
var uniteprice=resultXml.selectSingleNode("//q1:new_uniteprice").nodeTypedValue;
crmForm.all.new_uniteprice3.DataValue=Number(uniteprice);

//.试剂4................................................................................lookup 筛选
var field = crmForm.all.new_nameid4;
    var stauls="2";
    var name="一次性手套";
     // Ensure that search box is not visible in a lookup dialog
    field.lookupbrowse = 1;
  // Pass fetch xml through search value parameter
    field.AddParam("search",
     "<fetch mapping='logical'><entity name='new_reagent'>"
    + "<filter><condition attribute='new_stauls' operator='eq' value='"
    + stauls
    + "' /><condition attribute='new_name' operator='eq' value='"
    + name
    + "' /></filter></entity></fetch>");

//................................................................lookup赋初值
// Prepare variables to fetch accounts.
var fetchMapping = "logical";
var entityName = "new_reagent";
var firstColumn = "new_reagentid";
var secondColumn = "new_name";
var linkEntity = "systemuser";
var linkEntityTo ="owninguser";
var filterType = "and";
var conditionAttribute1 = "new_name";
var operator1 = "eq";
var value1 = "一次性手套";
var conditionAttribute2 = "new_stauls";
var operator2= "eq";
var value2 = "2";
var authenticationHeader = GenerateAuthenticationHeader();

// 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>"+
"<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<fetchXml>&lt;fetch mapping='"+fetchMapping+"'&gt;"+
"&lt;entity name='"+entityName+"'&gt;"+
"&lt;attribute name='"+firstColumn+"'/&gt;"+
"&lt;attribute name='"+secondColumn+"'/&gt;"+
//"&lt;link-entity name='"+linkEntity+"' to='"+linkEntityTo+"'&gt;"+
//"&lt;filter type='"+filterType+"'&gt;"+
"&lt;filter&gt;"+
"&lt;condition attribute='"+conditionAttribute1+"'"+
" operator='"+operator1+"' value='"+value1+"'/&gt;"+
"&lt;condition attribute='"+conditionAttribute2+"'"+
" operator='"+operator2+"' value='"+value2+"'/&gt;"+
"&lt;/filter&gt;"+
//"&lt;/link-entity&gt;"+
"&lt;/entity&gt;"+
"&lt;/fetch&gt;</fetchXml>"+
"</Fetch>"+
"</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/Fetch");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
 var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
 alert(msg);
}
// Process and display the results.
else
{

// Capture the result and UnEncode it.
var resultSet = new String();
resultSet = resultXml.text;
resultSet.replace('&lt;','<');
resultSet.replace('&gt;','>');

// Create an XML document that you can parse.
   var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
   oXmlDoc.async = false;
// Load the XML document that has the UnEncoded results.
   oXmlDoc.loadXML(resultSet);
// Display the results.
   var results = oXmlDoc.getElementsByTagName('result');

        for (i=0;i < results.length;i++)
    {
     var idValue = results[i].selectSingleNode('./new_reagentid').nodeTypedValue;
     var name = results[i].selectSingleNode('./new_name').nodeTypedValue;
    }

var start_id= results[0].selectSingleNode('./new_reagentid').nodeTypedValue;
var start_name=results[0].selectSingleNode('./new_name').nodeTypedValue;
if(results.length>1)
{
alert('一次性手套,不惟一,请选择!');
}
    //Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
   lookupItem.id = start_id;
   lookupItem.typename = 'new_reagent';
   lookupItem.name = start_name;
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.new_nameid4.DataValue = lookupData;
}
//.....................................................................retrieve和试剂有关的信息
// Prepare variables for a contact to retrieve.
var new_reagentid = start_id;
var authenticationHeader = GenerateAuthenticationHeader();

// 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>"+
"<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<entityName>new_reagent</entityName>"+
"<id>"+new_reagentid+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>new_number</q1:Attribute>"+
"<q1:Attribute>new_unites</q1:Attribute>"+
"<q1:Attribute>new_uniteprice</q1:Attribute>"+
"</q1:Attributes>"+
"</columnSet>"+
"</Retrieve>"+
"</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/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
var number=resultXml.selectSingleNode("//q1:new_number").nodeTypedValue;
crmForm.all.new_number4.DataValue=number;
var unites=resultXml.selectSingleNode("//q1:new_unites").nodeTypedValue;
crmForm.all.new_unite4.DataValue=unites;
var uniteprice=resultXml.selectSingleNode("//q1:new_uniteprice").nodeTypedValue;
crmForm.all.new_uniteprice4.DataValue=Number(uniteprice);
}

石蕊的主页 石蕊 | 初学一级 | 园豆:180
提问于:2011-01-19 11:25
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册