Select new record

I create a new record and save it. Then I want to pass this new record to the Servoy Jasper runReport function as a foundset. So I do a find to have only this new record in my foundset and pass it to Jasper. After that I call successfully loadAllRecords on the foundset. Then I try the selectRecord( pk ), but the new record can’t be selected, I assume it is not in the loaded foundset, because it is newly created. I also tried loadRecords( pk ), instead of the find, but it does also no solve the selection problem.

How can I select the new created record?

I tried the following.:

	if ( tmpid ) {
		documentID = tmpid;
		var clientNo = vonmand;
		
		var loaded = foundset.loadRecords( documentID );

		if ( loaded ) {
			jasperByte = plugins.jasperPluginRMI.runReport( foundset, buhaFakturaReport, null, "viewer", reportParams, docDefGlo.getDocumentLanguage( r_sprache ) );
		}
		
		var query = datasources.db.boss_sql.aufkopf.createSelect( );
		query.where.add( query.columns.vonmand.eq( clientNo ) );
		/** @type {JSFoundSet<db:/boss_sql/aufkopf>} */
		var fs = databaseManager.getFoundSet( query );

		for ( var fsI = 1; fsI <= fs.getSize( ); fsI++ ) {
			var rec = fs.getRecord( fsI );
			if ( rec.tmpid === documentID ) {
				application.output( 'record found: ' + tmpid + ' : ' + id );
			}
		}
		
		loaded = foundset.loadRecords( fs );
		var selected = foundset.selectRecord( documentID );
		application.output( 'record: ' + documentID + ' selected: ' + selected  );

record found: 133581 : 000003-2014-009608
record: 133581 selected: true

Then I can select the record. It seems to me, that it is a bug: SVY-7110.

selectRecord(pk) has this doc:

  • Select the record based on pk data.
  • Note that if the foundset has not loaded the record with the pk, selectrecord will fail.

so it is documented that if the record of that pk is not in memory yet then select record will not be able to find it, else we have to potentially fully load a foundset.

loadRecords(pk) should work if the record is saved and in the db. But that will ofcourse only load and show that specific pk, what does go wrong for you in this call then?

jcompagner:
selectRecord(pk) has this doc:

  • Select the record based on pk data.
  • Note that if the foundset has not loaded the record with the pk, selectrecord will fail.

so it is documented that if the record of that pk is not in memory yet then select record will not be able to find it, else we have to potentially fully load a foundset.

loadRecords(pk) should work if the record is saved and in the db. But that will ofcourse only load and show that specific pk, what does go wrong for you in this call then?

Yes, I read it. The record was newly created and saved to the database, so I assume it should now in my foundset. I stay on that record in the Smart Client, then I filter the foundset only for that record to pass the filtered foundset to Jasper. After that I load all records back, but then I can’t select that record, on which I stayed before and selection is switched to another record. So I assume the new created record should be also in that foundset or not?

This is desired behavior?

the doc says “Note that if the foundset has not loaded the record with the pk, selectrecord will fail.”

And if you do loadAll() not all records/pk’s are loaded!
only 200 (or 400 if you touched one after 200)

select pk only can select a pk that is already in memory. Not all pk’s are in memory when you just do loadAllRecordS() (not all records are loaded)

jcompagner:
the doc says “Note that if the foundset has not loaded the record with the pk, selectrecord will fail.”

And if you do loadAll() not all records/pk’s are loaded!
only 200 (or 400 if you touched one after 200)

select pk only can select a pk that is already in memory. Not all pk’s are in memory when you just do loadAllRecordS() (not all records are loaded)

Yeah, but I expect, that my new created (saved) record should be in memory after loadAllRecords, because before it was in memory.

So, you are saying, the my new created record should not be loaded, even though it was saved and in memory before?

How does loadAllRecords work in this case?

Just as Johan explained. LoadAllRecords flushes your foundset and only loads the first 200 records. If you touch record 199, it will get the next 200