In-Memory Datasources

Hi all, I saw this webinar and I’m starting to play with in-memory datasources. I’ve created a datasource named “organizations” with this fileds: organizationid, countryname, name. organizationid is the PK od the datasource.
In order to populate the “table” I’m using this code:

var ds  = databaseManager.createEmptyDataSet();
ds.createDataSource('organizations');

And then, using a for loop I’m trying to populate it using, i.e., this:

ds.addRow([100, 'Spain', 'Organization XYZ'])

.
But it throws an error.
If I use datasources.mem[‘organizations’].getColumnNames() I receive: “organizationid, countryname, name”. But If I use ds.getColumnNames() I only receive 2 fields: “countryname, name”, so I can’t set the organizationid field using ds.addRow()

What’s wrong in my code?

What error did you get?

I just made a simple test with a datasource test_id: UUID, test: String, test_2: String and then

var dsEmpty = databaseManager.createEmptyDataSet();
dsEmpty.addRow([application.getUUID(), 'test', 'test2']);
dsEmpty.addRow([application.getUUID(), 'test3', 'test4']);
dsEmpty.createDataSource('test');

To me it looks like you should fill your dataset and then create the datasource from it.

Also, you could simply do

var fs = datasources.mem.test.getFoundSet();
fs.loadAllRecords();
fs.deleteAllRecords();
fs.newRecord();
fs.test_id = application.getUUID();
fs.test = 'test';
fs.test_2 = 'test2';

so simply get a foundset of your in-memory table, clear all data and loop to create new records.

I’ve tried your first solution (fill the dataset and create the datasource) and it works.

Thanks, Patrick!