omitRecord does not always work

Discuss all problems you have with Servoy here. It might help to mention the Servoy version and Operating System version you are using

omitRecord does not always work

Postby deezzub » Tue Oct 01, 2013 10:11 am

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.:

Code: Select all
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.

Code: Select all
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

Code: Select all
omitOrDeleteRecord:true
omitOrDeleteRecord:true


Case if it fails: Video

Code: Select all
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?
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: omitRecord does not always work

Postby deezzub » Mon Oct 07, 2013 3:31 pm

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.
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: omitRecord does not always work

Postby lwjwillemsen » Mon Oct 07, 2013 5:00 pm

does not work if another record is already changed


You mean : and not saved?

Regards,
Lambert Willemsen
Vision Development BV
lwjwillemsen
 
Posts: 680
Joined: Sat Mar 14, 2009 5:39 pm
Location: The Netherlands

Re: omitRecord does not always work

Postby deezzub » Tue Oct 08, 2013 8:32 am

lwjwillemsen wrote:
does not work if another record is already changed


You mean : and not saved?


Yes.
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: omitRecord does not always work

Postby lwjwillemsen » Tue Oct 08, 2013 9:39 am

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.
Lambert Willemsen
Vision Development BV
lwjwillemsen
 
Posts: 680
Joined: Sat Mar 14, 2009 5:39 pm
Location: The Netherlands

Re: omitRecord does not always work

Postby ROCLASI » Tue Oct 08, 2013 11:28 am

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:
1) save the record before you omit it.
Code: Select all
databaseManager.saveData(foundset.getSelectedRecord());

2) revert any changed to the record before you omit it.
Code: Select all
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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium


Return to Discuss possible Issues and Bugs

Who is online

Users browsing this forum: No registered users and 8 guests