Really strange behaviour

This is really strange:
I have a table of items, each item have a “quantity” column, I need to print a sticker for every unit of some records so I’ve written a method that populates a temporary table with 1 record per item quantity, eg.:

item_id     q.ty
-----------------
1              2
2              3
3              2
-----------------
Tot. Q.ty=     7

generates:

sticker_id  item_id
--------------------
1                 1
2                 1
3                 2
4                 2
5                 2
6                 3
7                 3
--------------------
Tot. Records=7

So far so good, I now have some records to print and then delete so I decided to wrap the whole method in a transaction and after the printing rollback the transaction so that all records get deleted without the need to worry about others users printing other stickers at the same time.
The method is called from a FormInDialog based on table “group_of_items” that contains a portal to “items”.
Everything is fine except that after the transaction rollback the record showing in the formInDialog is changed!
I mean: I start from the record of group_of_items with id=3000, the printing is fine, the transaction rolled back, the stickers records deleted but suddenly the current record is changed to the record with id=1200.
After some test now I can assert that if I run the method from a record with id>1200 the method bring me back to the record with id=1200, if I run the method from a record with id<1200 everything is fine.
I’m going insane!

Debugging… debugging… I discovered that after the transaction rollback only the first 200 records from the group_of_items table are retrieved from the database and the record with id=1200 was in fact the 200th record. The strange thing is that if I try a controller.setSelectedIndex(original_idx) it simply doesn’t work. It seems it refuses to retrieve more than 200 records and so it cannot display record(original_idx).

This is the script, it’s quite easy so I didn’t translate the italian comments, the table group_of_items is called “ddt”, the table “items” is called “articoli” and the form based on stickers is called “ST_Etichetta_Articoli”.

// Salviamo i dati per evitare di perdere l'ultimo record ceckato
controller.saveData()

// Inzio la transazione
databaseManager.startTransaction()

// Creo i records in etichette
for ( var i = 1 ; i <= ddt_to_articoli.getSize() ; i++ )
{
	ddt_to_articoli.setSelectedIndex(i)
	
	// Creo solo i records marcati
	if ( ddt_to_articoli.marker == 1 )
		{
			for ( var j = ddt_to_articoli.quantita ; j > 0 ; j-- )
				{
					ddt_to_etichette.newRecord(true)
					ddt_to_etichette.articoli_id = ddt_to_articoli.articoli_id 
				}
		}
}

// Salvo i dati altrimenti perdo l'ultimo record creato
forms.ST_Etichetta_Articoli.controller.saveData();

// Stampo le etichette
forms.ST_Etichetta_Articoli.controller.print()

// Rollbacko la transazione in modo da cancellare i records temporanei
databaseManager.rollbackTransaction()

Nicola, servoy only retrieves records from the db in batches of 200 for performance reasons. If you want a specific record to be selected in the resulting foundset, search by primary key rather than index. For more details on the 200 limit, I bet a search would turn up a lot of hits.

You can also do something like:

var x = controller.duplicateFoundSet
... [your code here]
controller.loadRecords(x)

That will give you back the same set of records you were viewing before you executed your code.