locked
Problem with updating the ownerid of Lead using javascript RRS feed

  • Question

  • Hi...
     
    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?


    Thanks in advance...

    Thursday, February 5, 2009 1:20 PM

Answers

  • Hi,

    You should use the Assign method instead of Update to change ownership of a record.

    Hope that helps.

    Shafraz
    • Proposed as answer by Jim Glass Jr Thursday, February 5, 2009 8:31 PM
    • Marked as answer by Matt Parks Wednesday, May 6, 2009 10:14 PM
    Thursday, February 5, 2009 6:32 PM

All replies

  • Hi,

    You should use the Assign method instead of Update to change ownership of a record.

    Hope that helps.

    Shafraz
    • Proposed as answer by Jim Glass Jr Thursday, February 5, 2009 8:31 PM
    • Marked as answer by Matt Parks Wednesday, May 6, 2009 10:14 PM
    Thursday, February 5, 2009 6:32 PM
  • Hi Nasser...

    Could you provide me with an example?
    Friday, February 6, 2009 5:37 AM