locked
Account Entity not updating with Update Method using JScript RRS feed

  • Question

  • Hello,
    I want to update a field value in Account entity from its related Opportunity entity.

    I have a field called Franchise_Multi in both the Opportunity and Account entities. This is a custom field. When the Opportunity is Closed Won, the value from the Opportunity's Franchise_Multi field should be copied across to the Parent Account's Franchise_Multi field. I have written the following Script in the OnSave event of Opportunity entity. It gives me the final message that the account has been updated, but the field is not updated. Please help.

     var  lookupGUID1 =  lookupGUID.replace('{','');
     var  lookupGUID2 =  lookupGUID1.replace('}','');

     var authenticationHeader1 = 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'>"+
     authenticationHeader1+
     "<soap:Body>"+
     "<Update xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
     "<entity xsi:type='account'>"+
     "<new_franchise_multi>"+accProduct+"</new_franchise_multi>"+
     "<accountid>"+lookupGUID2+"</accountid>"+
     "</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("Account with id = "+lookupGUID2+" successfully updated.");
     }

    Regards,
    Madhur

    Thursday, September 24, 2009 11:30 AM

Answers

  • Hi, Madhur.

    Check this url . This approach will give you the possibility to recheck your SOAP. May be there are some issues in lookup updating.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Thursday, September 24, 2009 11:45 AM
    Moderator

All replies

  • Hi, Madhur.

    Check this url . This approach will give you the possibility to recheck your SOAP. May be there are some issues in lookup updating.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Thursday, September 24, 2009 11:45 AM
    Moderator
  • I want to update a field value in Account entity from its related Opportunity entity.

    Have you considered doing this with a workflow?  You could set the workflow to run when the Opportunity status changes to Closed and then update the related Account field with the vlaue.
    Best Regards, Donna
    Thursday, September 24, 2009 12:10 PM
  • Donna,
    I cant do it with a workflow since there can be multiple opportunities associated with an account. Previously the customer went only for 2 franchises but now he wants to add 2 more. Hence when the new opportunity is closed it should append to the already existing values in the franchise field. Hence I had to write a script in the OnSave event of the opportunity.

    Since we are using Dynamics CRM Online version I dont have much options other than workflow or script. Please correct me if my thinking is wrong.

    Thanks & Regards,
    Madhur

    Friday, September 25, 2009 3:26 AM
  • given your scenario, you're correct.  Best of luck with this change.
    Best Regards, Donna
    Friday, September 25, 2009 12:38 PM