Page 1 of 1

HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Thu Jul 05, 2012 4:25 pm
by hardina09
I am having combobox in form . I have created valuelist programmatically using below code

Code: Select all
<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.

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Thu Jul 05, 2012 4:39 pm
by ROCLASI
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.

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Thu Jul 05, 2012 5:39 pm
by hardina09
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

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Thu Jul 05, 2012 8:13 pm
by hardina09
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.

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Thu Jul 05, 2012 8:23 pm
by ROCLASI
hardina09 wrote: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
Code: Select all
var sql="SELECT dept_id || ' - ' || dept_name from departments";


Sybase/MSSQL
Code: Select all
var sql="SELECT dept_id + ' - ' + dept_name from departments";


Hope this helps.

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Fri Jul 06, 2012 8:52 am
by rioba
If you are not sure which backend Db is used you can first concatenate and then build the query
Code: Select all
var arg = dept_id + '-' + dept_name;
var sql="SELECT ' + arg  + ' FROM departments";

If you are using MySQL the right syntax could be
Code: Select all
var sql="SELECT CONCAT(dept_id,' + '-' + ',dept_name) FROM departments";

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Fri Jul 06, 2012 8:58 am
by ROCLASI
Hi Rioba,

rioba wrote:If you are not sure which backend Db is used you can first concatenate and then build the query
Code: Select all
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.

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Fri Jul 06, 2012 9:17 am
by rioba
Hi ROCLASI,

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

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

PostPosted: Wed Jul 11, 2012 11:17 pm
by hardina09
Thanks all.