Sorting an in-memory foundset

Questions, tips and tricks and techniques for scripting in Servoy

Sorting an in-memory foundset

Postby martijn.lutgens » Fri Mar 25, 2016 11:23 am

Hi there,

In our solution we have an in-memory foundset and I want to sort on a related value:

var resultData = databaseManager.createEmptyDataSet();
resultData.addColumn('contact_id', resultData.getMaxColumnIndex() + 1, JSColumn.TEXT);
resultData.addColumn('order_id', resultData.getMaxColumnIndex() + 1, JSColumn.TEXT);
resultData.addColumn('ledger_id', resultData.getMaxColumnIndex() + 1, JSColumn.TEXT);
resultData.addColumn('vat_code_id', resultData.getMaxColumnIndex() + 1, JSColumn.TEXT);
resultData.addColumn('amount', resultData.getMaxColumnIndex() + 1, JSColumn.NUMBER);
resultData.addColumn('vat_amount', resultData.getMaxColumnIndex() + 1, JSColumn.NUMBER);
resultData.addColumn('cost_code_id', resultData.getMaxColumnIndex() + 1, JSColumn.TEXT);
resultData.addColumn('type_order', resultData.getMaxColumnIndex() + 1, JSColumn.INTEGER);
resultData.addColumn('message', resultData.getMaxColumnIndex() + 1, JSColumn.TEXT);
resultData.addColumn('result_export_type', resultData.getMaxColumnIndex() + 1, JSColumn.INTEGER);
resultData.addColumn('is_success', resultData.getMaxColumnIndex() + 1, JSColumn.INTEGER);
resultData.addColumn('payment_condition_id', resultData.getMaxColumnIndex() + 1, JSColumn.TEXT);

var fsResultExport = databaseManager.getFoundSet(resultData.createDataSource('resultExport'));
if (!solutionModel.getRelation('resultExport_to_ledgers')) {
var resultExport_to_ledgers = solutionModel.newRelation('resultExport_to_ledgers', 'mem:resultExport', 'db:/autoflex_cloud/ledgers', JSRelation.LEFT_OUTER_JOIN);
fsResultExport.sort('resultExport_to_ledgers.ledger_number asc');

Somehow this sort doesn't work and the foundset is always sorted on _sv_rowid.

However when I do:
var recordExport = fsResultExport.getRecord(1);
It does return the correct ledger_number.

Am I missing something? :?
Posts: 2
Joined: Mon Apr 07, 2014 10:14 am

Re: Sorting an in-memory foundset

Postby rgansevles » Fri Mar 25, 2016 12:09 pm


You cannot sort across databases.
In case of a related sort, Servoy will create a order-by in a join created between the tables.
Cross-database this does not work.

The logs should say something like 'Cannot sort on dataprovider ...'

Rob Gansevles
User avatar
Posts: 1841
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Return to Methods

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests