HOW TO GET CUSTOM VALUELIST IN COMBOBOX

I am having combobox in form . I have created valuelist programmatically using below code

<somecode>
var ds = databaseManager.getDataSetByQuery(<servnm>,<sql>,arg,maxrow)
var arr1 = dataset.getColumnAsArray( 1 )
var arr2= dataset.getColumnAsArray( 2 )
application.setValueListItems( "valuelist'', arr1,arr2);

But thing is how to display valuelist in combobox. Any suggestions.

Hi,

You first have to create this valuelist with the name ‘valuelist’ in Developer, then assign that that the combobox. After this the code can fill the valuelist and it will show up.
Another way would be to do all this using the solutionModel.

Hope this helps.

I’m using SolutionModel to create valuelist. Valuelist is created but when assign to combobox its sitll empty. Can you please explain me in detail how to create valuelist and assign to combobox

I got to know that sql query in Dataset is wrong. Can anyone please correct the syntax

var sql=“SELECT dept_id” + “’ - '” +" dept_name from departments"; //syntax error.
var ds=databaseManager.getDatasetByQuery(‘servname’,sql,null,10);

Please suggest.

hardina09:
var sql=“SELECT dept_id” + “’ - '” +" dept_name from departments"; //syntax error.

So you want to concatenate the 3 values together ?
Depending on what database backend you are using you can use the following syntax:

PostgreSQL/Oracle

var sql="SELECT dept_id || ' - ' || dept_name from departments";

Sybase/MSSQL

var sql="SELECT dept_id + ' - ' + dept_name from departments";

Hope this helps.

If you are not sure which backend Db is used you can first concatenate and then build the query

var arg = dept_id + '-' + dept_name;
var sql="SELECT ' + arg  + ' FROM departments";

If you are using MySQL the right syntax could be

var sql="SELECT CONCAT(dept_id,' + '-' + ',dept_name) FROM departments";

Hi Rioba,

rioba:
If you are not sure which backend Db is used you can first concatenate and then build the query

var arg = dept_id + '-' + dept_name;

var sql=“SELECT ’ + arg + ’ FROM departments”;

That doesn’t work because then the database wants substract the value of dept_name from dept_id. Concatenation of columns in your query need to be done by SQL.
It’s a different matter if you want to pass values that you get from Servoy.

Hi ROCLASI,

I stand corrected. I treated them as variables, not columns. Sorry. I have therefore amended also the syntax for the MySQL query

Thanks all.