foundset.newRecord(true,false) triggers onSelection method?

I had assumed that if I create a new record using foundset.newRecord(true,false) (i.e. to load on top but NOT change the current selection) then the relevant form’s onRecordSelection method should not trigger as the selection is not being changed - however in my test solution it does always trigger, regardless of whether the selection is changed or not.

Is this the correct behaviour?

under investigation.

the current selected index is also not changed.
But the current selected record IS changed!!

Because if you have this:

record1
record2
record3

and you have record2 selected. then you do newRecord(true,false)

then you have this:

newRecord
record1
record2
record3

and record1 is selected!!! So the selectedIndex is not changed, but the record under the selection is changed because you add the record to the top.

So the behaviour is correct.

So David,

Does this work for you if you code it as:

foundset.newRecord(false,false)

Which should then add to the bottom of the foundset or does this then compromise the 200 record cache limit and push the record positions up one index place so that you are still out by one record position ?

Just interested !

Harry

if the foundset isn’t fully loaded (200+) then when you add a new row it will add that row on 201 but also load the other bunch (so it has now 400+)

So yes the new record isn’t really added to the bottom of the foundset because that is not really doable, because we don’t know how many more there are. there could be thousands or even much much more.

But are you saying that you see a swift in rows below 200?

so 190 is selected (recordX) and you do new then 190 isn’t selected anymore or recordX is not selected anymore?

Harry,

using foundset.newRecord(false,false); indeed does not trigger the onSelection method. What I was wanting to do was add a record to a table and then set the data in some fields on that record, all without triggering the form’s onSelection method - so, adding the record at the top made it easy because I could then get the record with ```
var record = foundset.getRecord(1)


However I have now solved it like this:

var n = foundset.getSize();
foundset.newRecord(false,false);
var record = foundset.getRecord(n+1);
record.description = ‘gotcha!’;


Following on from johan's comment re 200+ records I have checked this on a table with 400 records - I opened the file, which then listed the first 200 records of course. I ran the above script and the new record was indeed added as record 201 in the list (with all 400 records then loaded up) and the field(s) were set correctly in the right record.

Nice one, David !!

Harry

foundset.newRecord() returns the index on which the new record is created!

var n = foundset.newRecord(false,false);
var record = foundset.getRecord(n);
record.description = ‘gotcha!’;

Yep - I just got there myself - was about to post the same thing :lol: