Resources for IT Professionals > Dynamics Forums > CRM Development > Update query in CRM on on save event
Ask a questionAsk a question
 

AnswerUpdate query in CRM on on save event

Answers

  • Thursday, November 05, 2009 4:12 PMmardukes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    But the opportunityproductid i cannot get off my form.
    How can i get the opportuinityproductid? 


    Your original question: "...In the onsave of opportunityproduct ...."

    It's the current record -- crmForm.ObjectId!

    Not only can you get it, it IS it.

All Replies

  • Monday, November 02, 2009 11:26 AMNishant Rana-MCAD-MCTS-MCBMSS-MCBMSP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    You could call CrmService update method or could also call a custom web service which would update the required fields\table,  on the onSave event using Ajax.

    Regards,
    Nishant Rana

    http://nishantrana.wordpress.com
  • Monday, November 02, 2009 11:41 AMAndriy a33ik Butenko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Hi, Huub.

    This is unsupported customization but check following url:
    http://billoncrmtech.blogspot.com/2008/07/client-side-scripting-more-javascript_21.html

    I suggest you to use supported ways (webServices with JavaScript or Plugins).

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Proposed As Answer bymardukes Monday, November 02, 2009 8:14 PM
    •  
  • Monday, November 02, 2009 8:11 PMmardukes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    SQL injection.  You should NEVER put SQL ANYWHERE outside of the Management Studio or a stored procedure.  And you are not permitted to write stored procedures on the MSCRM data base.  You should use the CrmService.Update method.

  • Tuesday, November 03, 2009 7:16 AMHuub van de Wiel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Do you know where i can find the CrmService.Update method?
  • Tuesday, November 03, 2009 7:20 AMAndriy a33ik Butenko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Check following urls:

    CrmService Update method .
    Update method using JavaScript .
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
  • Tuesday, November 03, 2009 10:14 AMHuub van de Wiel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I get the error message: Unexpected error occured

    i used this method:

    var Nieuwbedrag = crmForm.all.priceperunit.DataValue;

    var Identificatie = crmForm.all.new_wijzigingsnummer.DataValue;

    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='OpportunityProduct'>"+

    "<priceperunit>"+Nieuwbedrag+"</priceperunit>"+

    "<new_wijzigingsnummer>"+Identificatie+"</new_wijzigingsnummer>"+

    "</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.

    else

    {

    alert("Wijziging met id = "+Identificatie+" successvol update.");

    }

  • Tuesday, November 03, 2009 10:16 AMAndriy a33ik Butenko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi.

    You have to fill opportunityproductid with correct identifier of opportunity product to make update.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
  • Tuesday, November 03, 2009 11:02 AMHuub van de Wiel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Sorry I don't get it
  • Tuesday, November 03, 2009 8:55 PMmardukes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    from the link Andriy provided you forgot this part: "<contactid>"+contactId+"</contactid>"+

    In your case you want <opportuinityproductid> instead of <contactid> because you have to identify which record you are updating.  You supplied two pieces of update data but not the record identity.  Yes the type is opportunityproduct (like tablename) but which record (like WHERE ID=...)

    CrmService.Update is talking to the database not your web form.

  • Wednesday, November 04, 2009 7:50 AMHuub van de Wiel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    But the opportunityproductid i cannot get off my form.
    How can i get the opportuinityproductid? 
  • Wednesday, November 04, 2009 8:02 AMAndriy a33ik Butenko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    But the opportunityproductid i cannot get off my form.
    How can i get the opportuinityproductid? 

    Hi, Huub.

    You can retrieve child opportunity products and identifiers (opportunityproductid) using RetrieveMultiple or Fetch .

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
  • Thursday, November 05, 2009 4:12 PMmardukes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    But the opportunityproductid i cannot get off my form.
    How can i get the opportuinityproductid? 


    Your original question: "...In the onsave of opportunityproduct ...."

    It's the current record -- crmForm.ObjectId!

    Not only can you get it, it IS it.