Hi Folks - I want to select a record by it’s PK. I don’t know its index but if I did I’d do getSelectedIndex.
Checked out getRecordIndex but I cant see how to format the PK to use it there?
Suggestion appreciated.
Hi Folks - I want to select a record by it’s PK. I don’t know its index but if I did I’d do getSelectedIndex.
Checked out getRecordIndex but I cant see how to format the PK to use it there?
Suggestion appreciated.
+1 to being able to select/get records by pk instead of index.
Hi,
did You look at foundset.selectRecord ?
Doing foundset.getRecord is not safe, because if the record is not in the (already loaded) foundset, it fails.
it can be done by doing this:
if(foundset.loadRecords(databaseManager.convertToDataSet([myPK]))) {
var vRecord = foundset.getRecord(1)
} else {
//the record with that pk is not found!
}
ofcourse the foundset/form, must be based on the same table where your PK comes from
Harjo:
Doing foundset.getRecord is not safe, because if the record is not in the (already loaded) foundset, it fails.it can be done by doing this:
if(foundset.loadRecords(databaseManager.convertToDataSet([myPK]))) {
var vRecord = foundset.getRecord(1)
} else {
//the record with that pk is not found!
}
ofcourse the foundset/form, must be based on the same table where your PK comes from
Thanks Harjo (you’ve been a bit prolific today on the forum ;-})
Wont that code reduce the foundset to the selected record though? What I need is to go-to the record with the specific PK and make it ‘selected’ but keeping the full foundset intact??
We use the following construction to select a specific record within a foundset by Pk (without reducing the foundset) :
var _select = <foundset>.selectRecord(<pk>)
if (_select == false) {
// go to last record in foundset
<foundset>.getRecord(databaseManager.getFoundSetCount(<foundset>)
var _select2 = <foundset>.selectRecord(<pk>)
if (_select2 == false) {
//.... record not in foundset
}
}
Thanks Hans I’ll give that one a try out. Cheers
Ian