I am trying to update the owner field for a particular lead using javascript based on leadid.
First of all my question is As owner field is a lookup field, if we change the ownerid of the lead then, will this changes the owner for that lead?
The code I used to update the ownerid for a lead is:
var leadId = "3006A97D-C2F3-DD11-B8DD-0003FF298905"; var ownerID = "304D27D5-39D0-DC11-AA32-0003FF33509E";
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>"+ "<Update xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ "<entity xsi:type='lead'>"+ "<ownerid>"+ownerID +"</ownerid>"+ "<leadid>"+leadId+"</leadid>"+ "</entity>"+ "</Update>"+ "</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/Update"); 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 a confirmation message and open the updated contact. else { alert("Lead with id = "+leadId+" successfully updated."); }
It is not giving any error but, the ownerid is not updating.
Can any one have an idea of how to update the owner using javascript?