Thanks,
So if i want my checkduplicate method to succeed, I should make sure that all new records are committed before the edited records when running my parent/child save in the UI as :
- Code: Select all
/**
* @param {JSEvent} event
*
* @properties={typeid:24,uuid:"782B9141-9AC4-4AF5-90BE-87B0416F348A"}
*/
function onActionSaveRecordChanges(event){
/**@type{String}*/
var frmEvent;
/**@type{JSFoundset}*/
var fsFormFoundset;
/**@type{JSRecord}*/
var rcParentRecord;
/** @type {{result:Boolean, message:String, failedrecords:JSRecord, htmlreport:String, exceptions:Array<ServoyException>}} */
var oGetResult;
/** @type {String} */
var sDialog;
/**@type{Boolean}*/
var bHasnewrecords;
/**@type{JSFoundSet}*/
var fsRelated;
/**@type{JSFoundSet}*/
var fsNewRelated;
frmEvent = event.getFormName();
fsFormFoundset=forms[frmEvent].foundset;
rcParentRecord = fsFormFoundset.getSelectedRecord();
fsRelated= rcParentRecord.parent_to_child;
//Saving main parent records if new record
if(rcParentRecord.isNew()){
oGetResult= globals.traSaveFoundsetRecord(rcParentRecord);
if(!oGetResult.result){
if(oGetResult.htmlreport!=null){
//show Error Report in new Window
}
else{
sDialog= globals.DIALOGS.showErrorDialog('Error',oGetResult.message,'Ok');
onActionRollBackRecordChanges(event);
return
}
}
}
//Saving any new related datas
bHasnewrecords= databaseManager.hasNewRecords(fsRelated);
if(bHasnewrecords){
fsNewRelated=fsRelated.duplicateFoundSet();
fsNewRelated=globals.traOmitExistingRecords(fsNewRelated);
oGetResult= globals.traSaveRecordsInFoundset(fsNewRelated);
if(!oGetResult.result){
if(oGetResult.htmlreport!=null){
//show Error Report in new Window
}
else{
sDialog= globals.DIALOGS.showErrorDialog('Error',oGetResult.message,'Ok');
onActionRollBackRecordChanges(event);
return
}
}
}
//General saving, takes care of any edits on existing records or/and in-memory deletes ( omitted )
oGetResult= globals.traSaveGeneral(rcParentRecord,fsRelated);
if(!oGetResult.result){
if(oGetResult.htmlreport!=null){
if(oGetResult.htmlreport!=null){
//show Error Report in new Window
}
else{
sDialog= globals.DIALOGS.showErrorDialog('Error',oGetResult.message,'Ok');
onActionRollBackRecordChanges(event);
return
}
}
else{
sDialog= globals.DIALOGS.showErrorDialog('Error',oGetResult.message,'Ok');
onActionRollBackRecordChanges(event);
return
}
}
else{
_super.onActionSaveRecordChanges(event);
}
}
Am i correct thinking that this way I can use the same global method not tied to any related foundset to check for duplicate entries within the OnRecordinsert/onRecordUpdate :
- getting the related foundset from a Query on the parent pk
- looping through records to check the record.getDataChanges() if this record is not already included in the omitted array ( records omitted that should be deleted when saving the parent record )
- checking through these changes if the new inserted record may be a duplicate ( same foreign keys associated )
Edit : should I read your answer "we try to do it based on order
or creation/updates" as "we try to do it based on order
of creation/updates" which then mean that new related records are treated before edited records in the related foundset ?