Problems with setValueListItems

I am trying to set a valuelist using setValueListItems that will display one value but save another. The valuelist displays, but it stores the displayed value instead of the real value.

I have included my code for the method below from the get dataset on. I have verified that both arrays at the end are loaded with the correct values. I also have a blank valuelist set to custom values. It is almost like the second array is completely ignored by the statement.

Any suggestions will be appreciated.

Thanks,
Jason

var dataset = databaseManager.getDataSetByQuery(‘ddcinfo’, query, args, maxReturnedRows);

var realvalue = new Array;
var displayvalue = new Array;
realvalue = dataset.getColumnAsArray(2);
displayvalue = dataset.getColumnAsArray(1);

application.setValueListItems( valuelistname, displayvalue, realvalue);

Hi Jason,

This is code is not exact, but should help

var dataset = databaseManager.getDataSetByQuery(‘ddcinfo’, query, args, maxReturnedRows);

//Convert data set to array
var RealValue= dataset .getColumnAsArray(1);
var DisplayValue= dataset.getColumnAsArray(2);

//Assign array to value list
application.setValueListItems(‘MyValueList’, RealValue, DisplayValue)

Isn’t that the same code, without the array defs before the assignment? It looks like you flopped the array var assignment to, but that doesn’t seem to change the meaning of things. The only other thing I see is a qouted name value list, versus a variable as indicated in the first method.

So I’m not sure how this would help. Can anyone advise me on this?

Well, I use this all the time , there must be some other issue. I am sure someone will be able to troubleshoot.
Erich

You say the display value is stored. Is the column a text column (the usual setup is display=text, return=id)? Could you post the whole code plus information about the column in question? Is the field set to non editable?

Mr. Meunier,

You can either call this a bug or work-around, but if you create a custom value list, and then set it as the value list on a field, it will display as a drop-down (white box with arrow in it). But if you first set it as a value list of database values, and then set it as the value list on the field, it will set it to a select only combo box (all gray, cannot be typed in). Then, you have to modify the value list and set it back to custom. Then it works.

I’d call it a bug…or at least its how it works on our system with Mac.

Thanks, that fixed it.

Thanks for all of your help. I would agree this is a bug, mainly because on a Windows machine, you would not even be able to differentiate between the two different types of comboboxes unless you go to a different look and feel.

Hope the guys at Servoy see this…

Jason

You know what’s really sad…Our desks are about 15 feet from eachother and we’re figuring it out on the Servoy Forums :idea:

The simpler way I find to set valuelists when using a query is to use the dataset itself when the query is only returning the id value and the display value. So if you have:

var query = ‘select display_value, id from table’
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 25);

You can set the valuelist by just doing this:

application.setValueListItems(‘valuelistname’,dataset);

without doing the ‘getColumnAsArray’. Maybe there is some downside to doing it this way but I’ve never found one and it is less code.

I thought about that, but what if you want to display the first column and return the second column from your dataset. Does it work properly in that regard or do you have to do some other work with it. I am guessing that it displays both columns and returns both columns in the senario you have listed here.

Jason

just try it :)

Yeah, thanks Patrick…but I got it working now, so maybe the next time. I figured John already knew if it worked. :)

Not sure it was clarified but just using the dataset directly it will return the second item in your select statement and display the first.

That is cool. Thanks for the tip. I do believe there is an issue still with the combobox.

Thanks again

Jason