Hi,
I have a form that contains a header record. When the header record is saved. I have an Onsave event that is fired to execute a write to a different entity and reset fields on the exiting header entity.
I know I can use a plugin using a Post Operation. I want to try and not to create a plugin for this.
Here's my question. What happen if I do a write to a different entity and also update the existing entity.
Or maybe I should be asking how can I force the header entity to save first then create the detail entity.
What is the best approach to doing something like this?
Here my javascript function:
Please note that the "createEntity" is another function in my javascript.
function CalibrationDetailTransaction() {
var isCreateTransactionDate = Xrm.Page.getAttribute("new_iscreatenewtransactiondate").getInitialValue();
if (isCreateTransactionDate !== true)
return;
//Now create the next new calibration transaction dates
var new_calibrationdetail = object();
var calibrationGuid = Xrm.Page.data.entity.getId().replace(/{/g,'').replace(/}/g,'');
var newName = Xrm.Page.getAttribute("new_name").getValue();
//Calibration Reference
new_calibrationdetail.new_calibrationid = {
Id: calibrationGuid,
LogicalName: "new_calibration",
Name: newName
};
new_calibrationdetail.new_removedon = Xrm.Page.getAttribute("new_removedon").getValue();
new_calibrationdetail.new_sendon = Xrm.Page.getAttribute("new_sendon").getValue();
new_calibrationdetail.new_receivedon = Xrm.Page.getAttribute("new_receivedon").getValue();
new_calibrationdetail.new_nextdueon = Xrm.Page.getAttribute("new_nextdueon").getText();
new_calibrationdetail.new_lastcalibrationon = Xrm.Page.getAttribute("new_lastcalibrationon").getValue();
new_calibrationdetail.new_inserviceon = Xrm.Page.getAttribute("new_inserviceon").getValue();
new_calibrationdetail.statuscode = { Value: 100000002 };; //File Number
//Reset the header calibration dates
Xrm.Page.getAttribute("new_removedon").setValue("");
Xrm.Page.getAttribute("new_sendon").setValue("");
Xrm.Page.getAttribute("new_receivedon").setValue("");
Xrm.Page.getAttribute("new_nextdueon").setValue("");
Xrm.Page.getAttribute("new_lastcalibrationon").setValue("");
Xrm.Page.getAttribute("new_inserviceon").setValue("");
Xrm.Page.getAttribute("new_iscreatenewtransactiondate").setValue(false);
//Create a new detail calibration transaction Dates
createEntity(entityName, new_calibrationdetail);
}








