selectRecord with multiple pk values

I want to programatically move to a specific record in a foundset. I don’t want to do a find because I want the user to be able to move forward and back from the foundset at that point.

forms.companies.foundset.selectRecord(pk_id) seems to work fine for this purpose if the table one which the form is based has a primary key of one field, BUT if the primary key consists of two or more fields it doesn’t work (even though the documentation says it should – see below)

What can I do about this?

Function selectRecord
Description Selects the record(s) based on the specified pk (primary key) data in the foundset
of the specified form.
Syntax
forms.formName.foundset.selectRecord(pkid1,pkid2..pkidN)
Parameters
pkid1, pkid2…pkidN - the specified pkid(s)
Example forms.companies.foundset.selectRecord(pk_id);

Hi Glenn,

I couldn’t reproduce this.
Can you send me a sample solution.

Thanks.

Hi Glenn,

I can’t properly test your solution cause it’s calling a stored procedure.
But I did some simple tests:

foundset.selectRecord(1,3)
OR
var x = new Array()
x[0] = 1
x[1] = 3
foundset.selectRecord(x)

…which selected a record fine.

So I suspect that your pkVals variable isn’t accepted by the selectRecord() method.
Maybe because it’s a String instead of integers or array?
(the parameters have to map properly to the pk’s)

You can also do some simple validating using following code:
var x = 5
application.output( typeof(x) );

“typeof” returns the actual type of a variable (Object, int , string etc..)

Try to test again using hard coded variables and work your way back to your original code.
My guess is that pkVals is a String and not an Array.

OK. Thanks.

You might want to advice the people who write the documentation to make this change. The documentation says:

forms.formName.foundset.selectRecord(pkid1,pkid2..pkidN)

Which clearly makes it seem like the list is supposed to be a string and not an array.

Thanks again.

As maarten pointed out, both are possible (an array is not needed)

Maarten,

In your explanation of how to work with multiple PK column, you say: Check if the values that you give as parameters are integers/number.

In my case, I have a 5 column PK, of which two columns are Text columns. Should it still work or…?

Ths is my code:

foundset.selectRecord(1675,stringA',49,10,'StringB');
plugins.dialogs.showInfoDialog('Title',oneColumnValue,'OK');

I put the PK Column values in in the order which the columns are in the table.

I have a small test form with 10 records including the one with this PK, but when I execute this command, the pointer does not go to this specific record.

Paul

Hi Paul,

In your explanation of how to work with multiple PK column, you say: Check if the values that you give as parameters are integers/number.
In my case, I have a 5 column PK, of which two columns are Text columns. Should it still work or…?

Strings should also work. In the sample above, the pk’s were only integers, so that’s why.

I did a test with 3 pk’s (int,string,int) which worked fine.

Can you send me a sample with reproducable error?

BTW: I noticed in your code above that stringA is missing a left quote.
maybe just an error in this post?

Turned out that the order of pk’s wasn’t correct.
Please note that Servoy ALWAYS handles multi pk keys in alphabetical fashion and NOT in creation order.
This is more consistent , since eg. columns may be dropped/created, mixing up the creation order again.

Additional note:
Sample code + manual will be adjusted, since this wasn’t clearly pointed out.

Thanks for reporting Paul.