valuelist version 6.1

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?

Hi Jos,

This looks like the same discussion we have had a while back. See https://www.servoy.com/forum/viewtopic.php?f=22&t=18319&hilit=+valuelist

Especially Johan’s comment:

i think this is because we think we can’t map to a display value or something and then we just show the id.

this happens for example a lot when the valuelist is based on a relation with a foreign key id → id to name
then when we cant resolve the relation because the id → id relation is just not there we see a null and fallback to the name
I guess in your situation it also does that. We just don’t expect that the display names are null when there are id’s

In your case it is for a user also very strange to see that list. If sees a list with 5 values, 2 of them are just empty/the same
So it just picks one? and that id is then set? That doesn’t make to much sense to me then it is just random what users can pick both id’s are just the same