jueves, 5 de julio de 2012

CrmService.Retrieve Method Using JScript CRM4

/*-----------------Parent Accountid---------------------------*/
 if (crmForm.all.parentaccountid.DataValue != null && crmForm.all.ppc_rfc_para_fact.DataValue==2) {
 var parentacct = crmForm.all.parentaccountid;
 var entidad = "account";
 var atributo1 = "ppc_numeronit";
 var atributo2 ="ppc_actualizado";
 try {
 var parentaccountid = parentacct.DataValue[0].id;
 var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); xmlhttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false);
 xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve"); //xmlhttp.setRequestHeader("Content-Length", xml.length); var soapBody = "" + "" + "" + entidad + "" + "" + parentaccountid + "" + "" + "" + "" + atributo1 + "" + "" + atributo2 + "" + "" + "" + "" + ""; var soapXml = ""; soapXml += GenerateAuthenticationHeader(); soapXml += soapBody; soapXml += ""; xmlhttp.setRequestHeader("Content-Length", soapXml.length);
xmlhttp.send(soapXml);
 // Capture the result.
 var resultXml = xmlhttp.responseXML; // Check for errors.
 var errorCount = resultXml.selectNodes('//error').length;
 if (errorCount != 0) {
 var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg);
 } // Display the retrieved value.
 else {
 //alert(resultXml.selectSingleNode('//q1:'+atributo1).nodeTypedValue); //alert(resultXml.selectSingleNode('//q1:'+atributo2).nodeTypedValue);
 if (resultXml.selectSingleNode('//q1:' + atributo2).nodeTypedValue == 1)
{
 crmForm.all.ppc_num_nit_cc_fact.DataValue = resultXml.selectSingleNode('//q1:' + atributo1).nodeTypedValue;
 } else {
 alert('La cuenta la cuenta Primaria no ha \n sido enviada a Solomon.');                           crmForm.all.ppc_num_nit_cc_fact.DataValue = '';
     }
   }
 }
 catch (e) {
   alert(e.message);
  }
}

No hay comentarios: