locked
Change a record's owner with javascript RRS feed

  • Question

  • Hello,

    I want to change owner a custom entity's record with javascript.
    I tried to write a JS code, but it doesn't work.

    What is the wrong this code. Or could you help me please?

    Regards
    Yildiray

    var userid = "86B2EBFA-BA6A-DD11-84D4-0016357F5F41"; // This is new Owner ID
    var recordid = "EE11FC83-7C33-E011-817F-0016357F5F41"; // This is the record ID which will be updated.... I don't know is it true?
    var target = "TargetOwnedDynamic";                                  // This is for custom entity

    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\">" +
    header +
    "  <soap:Body>" +
    "    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
    "      <Request xsi:type=\"AssignRequest\">" +
    "        <Target xsi:type=\""+ target +"\">" +
    "          <EntityName>new_entityname</EntityName>"+
    "          <EntityId>"+ recordid +"</EntityId>" +
    "        </Target>" +
    "        <Assignee>" +
    "          <PrincipalId xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">"+ userid +"</PrincipalId>" +
    "          <Type xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">User</Type>" +
    "        </Assignee>" +
    "      </Request>" +
    "    </Execute>" +
    "  </soap:Body>" +
    "</soap:Envelope>" +
    "";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;

     


    MS CRM
    • Moved by Kimberlee Johnson Tuesday, February 8, 2011 3:26 PM Jscript question (From:Dynamics CRM)
    Tuesday, February 8, 2011 3:03 PM

Answers

All replies