Loading an array

Is it possible to prepare an array of pks, then load these records?

var array1 = new Array(2844,2845,2846);
array1.push(3441);
controller.loadRecords(array1);

Nothing is loaded, no error message. How does one convert an array into an appropriate form for loading?

Hi Morley,

There are some functions in the database manager to deal with conversions of arrays to foundsets

// converts a foundset to a dataset
var dataset = databaseManager.convertToDataSet(foundset);
// convects an array to a dataset
var dataset = databaseManager.convertToDataSet(new Array(1,2,3,4,5,6));

Then you can use

controller.loadRecords(dataset);

Thanks Christian. Missed it on my pass through the docs.

Something’s wrong.

var array1 = new Array(2844,2845,2846);
array1.push(3441);
var dataset = databaseManager.convertToDataSet(array1);
controller.loadRecords(dataset);

Debugger identifies the variable array1 as “2844,2845,2846,3441”, four values but only the first three records are loaded.

Just a quick thought:
Check if the record id ‘3441’ is indeed in the database.

What do you get when you do

var query = 'SELECT table.primary_key FROM table WHERE table.primary_key IN (2844,2845,2846,3441) ORDER BY table.primary_key';
controller.loadRecords(query);

??

patrick:
What do you get when you do

var query = 'SELECT table.primary_key FROM table WHERE table.primary_key IN (2844,2845,2846,3441) ORDER BY table.primary_key';

controller.loadRecords(query);

Robert, yes the record is indeed there.
Patrick, yes the SQL query route works.

Essentially I’m trying to add a specific PK to an existing foundset. Turning the foundset into an array and pushing the extra PK works. If a SQL query can use a named array, we then have a complete answer. My experiments to replace the PK string with a named array thus far have not worked.

this:

var array1 = new Array(2844,2845,2846);
array1.push(3441);
var dataset = databaseManager.convertToDataSet(array1);
controller.loadRecords(dataset);

was a bug
fixed for 2.2.1