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);
resultExport_to_ledgers.newRelationItem('ledger_id','=','ledger_id');
}
fsResultExport.loadRecords(getResultExportTypeQuery(scopes.accountancy_package_settings.RESULT_EXPORT_TYPES.LEDGER));
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);
application.output(recordExport['resultExport_to_ledgers'].ledger_number);
It does return the correct ledger_number.
Am I missing something?
![Confused :?](./images/smilies/icon_confused.gif)