foundset.GetSelectedRecord() is null

Hi guys,

I have a if condition onRecordSelection in my form that is it supposed to check if the foundset has any records in it and if the selected record is new or not so that I can then decide if I need to have some fields enabled or not. Here is my if condition:

if(utils.hasRecords(foundset) && !foundset.getSelectedRecord().isNew()){
do somthing…
}

The problem is that some times in the second condition “foundset.getSeletedRecord” is null for whatever reason and therefore I tries to call “isNew()” from null and it pops up an error! Based on what I know when we get to the if condition it will check the first condition and if it was satisfactory then it will check the second one, so when it checks for isNew() on the selected record we should have atleast on record in the foundset that is selected.

Any help would be appreciated.

Regards,
Siavash

Which version are you using? On the release notes of 6.1 (https://www.servoy.com/forum/viewtopic.php?f=22&t=18516&p=102503#p102503) it says:

Form.onRecordSelection is also fired when the selection is being set to none (-1) if an empty foundset is set. (so foundset.getSelectedRecord() can return null)

Maybe that has to do with it?

Thanks for your reply jd2p, That might be the problem as when I add another condition to my if statement to check foundset != null, the error seems to be gone. But what I don’t understand is firstly we don’t set the form foundset to empty (it is always set to default in all of our forms) and that shouldn’t be the case of “an empty foundset is set”. After all, sometimes when I’m in debug mode and I check the foundset, it has 2 3 records in it and it still gives me null for foundset.getSelectedRecord() and even if the foundset doesn’t have any records in it, it shouldn’t pass the first condition and check for the second condition from null!

Cheers,
siavash

siavash.roozbehan:
That might be the problem as when I add another condition to my if statement to check foundset != null, the error seems to be gone.

If ‘foundset’ is null (adding that check solves the problem) then it’s not a selected record problem; where do you get your foundset from? When is that code executed? It seems the foundset itself is null, not the selection.

You also mentioned that, while debugging, the foundset has records but no selection. Do you have a way of reproducing this?
Which version are you using?

ok I use version 6.1.2 - build 1421. I was debuging the code again on yesterday and I realized the problem occurs again even with the extra condition (foundset != null) so that actually didn’t solve the problem. The foundset is never null, it might have no records in it but the foundset is not null. The problem is the foundset.getSelectedRecord() which returns null sometimes as I mentioned even when I have records in the foundset. I tried to use foundset.getSelectedIndex() instead of foundset.getSelectedRecord() an surprisingly at the time the foundset.getSelectedRecord() returns null, .getSelectedIndex() returns the corrent index number so I assume there is a bug in this version as in this case it shows actually there is a selected index and there is a problem with the method getSelectedRecord()…again replacing the method with getSelectedIndex() seem to fix the issue but I need to do some more testing so that I can see if the problem occurs again. Anyone of you guys have noticed such a problem in the new release of servoy?

Cheers,
Siavash

Hmm. If you find a way to reproduce this I’d like to see it. But it might be hard to reproduce.
Try to output/log the values of getSelectedRecord(), getSelectedIndex() and getSize() when utils.hasRecords() is true.
This way we can see if that was a valid selected index (it might have been > size).

There was a similar problem with selected record - reported in 3 cases: SVY-3085, SVY-3169, SVY-1710; it might be the same one. That issue is fixed in 6.0.9/6.1.3.

Hi

Same issue here. We migrated to Servoy 7.1 and find, that the application gets errors we didn’t have before (Servoy 5.2.16). The problem is, that onRecordSelection sometimes gets triggered twice. The first time without a selected record. We have to add code, that checks this. Quite annoying.

Any idea/help/fix?

Kind regards
Birgit