HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby hardina09 » Thu Jul 05, 2012 4:25 pm

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.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby ROCLASI » Thu Jul 05, 2012 4:39 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby hardina09 » Thu Jul 05, 2012 5:39 pm

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
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby hardina09 » Thu Jul 05, 2012 8:13 pm

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
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby ROCLASI » Thu Jul 05, 2012 8:23 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby rioba » Fri Jul 06, 2012 8:52 am

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";
Last edited by rioba on Fri Jul 06, 2012 9:14 am, edited 1 time in total.
rioba
 
Posts: 242
Joined: Mon Aug 08, 2005 4:26 pm

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby ROCLASI » Fri Jul 06, 2012 8:58 am

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby rioba » Fri Jul 06, 2012 9:17 am

Hi ROCLASI,

I stand corrected. I treated them as variables, not columns. Sorry. I have therefore amended also the syntax for the MySQL query
rioba
 
Posts: 242
Joined: Mon Aug 08, 2005 4:26 pm

Re: HOW TO GET CUSTOM VALUELIST IN COMBOBOX

Postby hardina09 » Wed Jul 11, 2012 11:17 pm

Thanks all.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm


Return to How To

Who is online

Users browsing this forum: No registered users and 11 guests