I try to omit records, but sometimes it does not work for every record. The following code is executed if I omit a selected record.:
function omitOrDeleteRecord( relation ) {
var formName = controller.getName();
if ( accCheck.isInEditMode( formName ) ) {
var success = foundset[ relation ].omitRecord();
application.output( 'omitOrDeleteRecord:' + success );
} else {
bla();
}
}
The omitOrDeleteRecord function is called from the deletePosition function.
function deletePosition( event ) {
var formName = controller.getName(),
selectedComIndexBefore = tckopf_to_tckom.getSelectedIndex(),
selectedOposIndexBefore = tckopf_to_tcpos.getSelectedIndex();
if ( accCheck.addOrEditAllowed( formName ) ) {
if ( elements.tabs_positions.tabIndex == 1 ) { // in commissions table
calculateNetValue( { 'formName' : formName, 'commissionValue' : tckopf_to_tckom.kommission } );
omitOrDeleteRecord( 'tckopf_to_tckom' );
recalculatePositionNumbers( selectedComIndexBefore, 'tckopf_to_tckom' );
} else {
blub();
}
}
}
I have 2 (relation) records, that I try to delete.
Case if it works: Video
omitOrDeleteRecord:true
omitOrDeleteRecord:true
Case if it fails: Video
omitOrDeleteRecord:false
omitOrDeleteRecord:true
omitOrDeleteRecord:false
omitOrDeleteRecord:false
Is this a bug or do I something wrong? In which cases a record can’t be omitted?
It seems that the function: omitRecord( ) does not work if another record is already changed. Is this a desired behaviour by this function?
In the docs about omitRecord there is nothing documented about this.
omitRecord
BooleanomitRecord()
Omit current record, to be shown with loadOmittedRecords.
If the foundset is in multiselect mode, all selected records are omitted (when no index parameter is used).
Note: The omitted records list is discarded when these functions are executed: loadAllRecords, loadRecords(dataset), loadRecords(sqlstring), invertRecords()
Returns
Boolean – boolean true if all records could be omitted.
omitRecord
BooleanomitRecord(index)
Omit record under the given index, to be shown with loadOmittedRecords.
If the foundset is in multiselect mode, all selected records are omitted (when no index parameter is used).
Note: The omitted records list is discarded when these functions are executed: loadAllRecords, loadRecords(dataset), loadRecords(sqlstring), invertRecords()
Parameters
{Number} index – The index of the record to omit.
Returns
Boolean – boolean true if all records could be omitted.
does not work if another record is already changed
You mean : and not saved?
Regards,
Servoy cannot query the database for data when unsaved data exists in memory.
Omitting records changes the sql query in your foundset, omitting records is not only in memory.
Actually omitting a record just means that Servoy removes the record from the loaded (in memory) foundset and keeps track of the PK value(s) so that subsequent queries will not load these omitted records.
But since your record has unsaved data Servoy won’t omit the record so you don’t loose any changes.
So you can do 2 things:
- save the record before you omit it.
databaseManager.saveData(foundset.getSelectedRecord());
- revert any changed to the record before you omit it.
foundset.getSelectedRecord().revertChanges();
The second option has one downside and that is if this is a newly created (unsaved) record then the revertChanges() will already remove the record from the foundset. So if you trigger an omit after this you remove/omit 2 records instead of 1. If you prefer to revert instead of save then you could create a little omit function that checks for these things.
Hope this helps.