Tuesday, March 6, 2012

inherit account information from contact

Hello all,
Here i have code that inherit account information from contact
add this code in the OnChange event of the parentcustomerid field



var accountid = crmForm.all.parentcustomerid.DataValue[0].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>account</entityName>"+
"<id>"+accountid+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>transactioncurrencyid</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;

// 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:transactioncurrencyid").nodeTypedValue);
}




// Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
// Create an object to add to the array.
   var lookupItem= new Object();
// Set the id, typename, and name properties to the object.
   lookupItem.id = resultXml.selectSingleNode("//q1:transactioncurrencyid").nodeTypedValue;
   lookupItem.typename = 'transactioncurrency';
   lookupItem.name = resultXml.selectSingleNode("//q1:transactioncurrencyid").getAttribute("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.transactioncurrencyid.DataValue = lookupData;


Now u can change the code as per your requirement.
if u have any doubt then u can ask freely

No comments:

Post a Comment