I use this script to populate a valuelist:
var dataSet = databaseManager.createEmptyDataSet(0,[‘name’,‘name_id’]);
if(some_id != 0 && someother_id != 0){
var query = 'select name,name_id from myTable where some_id = ’ + some_id + ’ and someother_id = ’ + someother_id;
dataSet = databaseManager.getDataSetByQuery(‘myDatabase’,query,null,-1);
}
dataSet.addRow(1,[‘Choose a name’,0]);
application.setValueListItems(‘names’,dataSet);
The result is a valuelist. However if the visible value ‘name’ is not unique (i.e. the name value is one or more times the same) but the ‘name_id’ is (is pk so has to be unique), the value chosen does not always select the right ‘name_id’. It looks like that after a choice has been made the list searches for the first occurance of the visible ‘name’ value and selects the ‘name_id’ of that occurance, even when the second occurance of the ‘name’ value was chosen.
The whole thing works correct when I alter the script like this (works for a mySQL db):
var dataSet = databaseManager.createEmptyDataSet(0,[‘name’,‘name_id’]);
if(some_id != 0 && someother_id != 0){
var query = 'select concat(name_id," ",name),name_id from myTable where some_id = ’ + some_id + ’ and someother_id = ’ + someother_id;
dataSet = databaseManager.getDataSetByQuery(‘myDatabase’,query,null,-1);
}
dataSet.addRow(1,[‘Choose a name’,0]);
application.setValueListItems(‘names’,dataSet);
now the visible values in the list become unique and the right id will be chosen.
Is this a bug? Or was it made on purpose?