Update query in CRM on on save event
- Is it possible to put a sql update query in the customizations?
In the onsave of opportunityproduct .
Answers
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.
- Marked As Answer byHuub van de Wiel Monday, November 09, 2009 8:55 AM
All Replies
- 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 - 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
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.
- Do you know where i can find the CrmService.Update method?
- Check following urls:
CrmService Update method .
Update method using JavaScript .
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com - 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.");
}
- 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 - Sorry I don't get it
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.
- But the opportunityproductid i cannot get off my form.
How can i get the opportuinityproductid? 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.comBut 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.
- Marked As Answer byHuub van de Wiel Monday, November 09, 2009 8:55 AM

