jcompagner:
this is logical, the records you hold on to are exactly the same record that gets reverted (if you do record.value = x you want that it really will change the actual value of the ‘real’ record)
Why is there no ‘virtual’ record, that has no binding to the database / memory or to the record stored in the database / memory. I think it is really useful, if this would be possible and the possibility to override the record in the database with the ‘virtual’ record (only for values that can not cause data inconsistencies).
jcompagner:
If you really want to keep the data you have to loop over the records
and copy the record.getChangedData() into an array instead of the record itself.
I found this solution, but it would be great if Servoy has a built in function for this.
/**
* Backup record changes for later reusing if they needed.
*
* @param {String} formName , the name of the form to get the foundset for backup the record changes.
* @param {String} foundSet , the foundset or relation name to backup its changes.
* @param {String} uid , a column name as unique record identifier in the context of the record in the foundset.
*
* @return {Array<Array<Array<Object>>>} the array with the changed values for the records and "null" if there are no changed record values.
*
* @public
* @since 02.10.2013
* @version 04.10.2013 14:11:36
*
* @author deezzub
*/
function backupRecordChanges( formName, foundSet, uid ) {
var changedData,
changedRow,
editedRec,
editedRecs,
/** @type {JSFoundSet} */
fs = forms[ formName ][ foundSet ],
recBackup,
recsBackup = [ ],
recUid;
if ( databaseManager.hasRecordChanges( fs ) ) {
editedRecs = databaseManager.getEditedRecords( fs );
for ( var recIndex = 0; recIndex < editedRecs.length; recIndex++ ) {
/** @type {JSRecord} */
editedRec = editedRecs [ recIndex ],
changedData = editedRec.getChangedData( ),
recBackup = [ ],
recUid = editedRecs [ recIndex ][ uid ];
for ( var rowIndex = 1; rowIndex <= changedData.getMaxRowIndex( ); rowIndex++ ) {
changedRow = [ ];
for ( var columnIndex = 1; columnIndex <= 3; columnIndex++ ) {
changedRow[ columnIndex - 1 ] = changedData.getValue( rowIndex, columnIndex );
}
recBackup[ 0 ] = recUid;
recBackup[ rowIndex ] = changedRow
}
recsBackup[ recIndex ] = recBackup;
}
} else {
recsBackup = null;
}
return recsBackup;
}
david:
Easy way to duplicate a record:
// get foundset of source record
var serverName = srcRecord.foundset.getServerName()
var tableName = srcRecord.foundset.getTableName()
var fsThis = databaseManager.getFoundSet(serverName,tableName)
// create duplicate record and copy data
var destRecord = fsThis.getRecord(fsThis.newRecord(false,true))
databaseManager.copyMatchingFields(srcRecord,destRecord,overwriteOK[0] || false)
Use a different destination foundset (with identical fields) to archive records.
<a class="postlink" href="http://community.data-sutra.com/projects/datasutra/repository/entry/trunk/_ds_CODE_resources/globals.js#L4279">http://community.data-sutra.com/project ... s.js#L4279</a> for a utility function that copies a record and all related records (Servoy 3 to 5 era code but it still works).
Can I use the following to get a foundset, that has the edited records, but it’s not changed if I changed the source foundset?
var fsCopy = foundset[ relation ].duplicateFoundSet();
fsCopy.unrelate();