Dynamic list from multi columns

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

azaleas
Ebase User
Posts: 81
Joined: Thu Jul 30, 2015 12:44 pm

Dynamic list from multi columns

#1

Postby azaleas » Mon Aug 24, 2015 10:35 am

Is there a way to create a Dynamic list from multiple columns of DB table? i.e ID+Name? Just as a Display value?
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#2

Postby dvanhussel » Mon Aug 24, 2015 10:49 am

Hi azaleas,

You can do this with a custom list. For example, something like this.
This assumes that the user data is fetched into a table called USERS:

Code: Select all

var userTable = tables.USERS;
var users = fields.USERDROPDOWN.createCustomList();

userTable.fetchTable();

var rows = userTable.getRows();
while(rows.next()){
	var usernameDisplay = userTable.ID.value + ' - '+userTable.NAME.value	;
	users.add(usernameDisplay, userTable.ID.value);
}

The list will contain the ID as fieldvalue and a concatenation of the ID and USERNAME as displayvalue. The list is associated with the field USERDROPDOWN.

Regards,

David
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#3

Postby Jon » Mon Aug 24, 2015 11:16 am

Or you could do it by concatenating fields in the select statement of the Dynamic List e.g.

Code: Select all

select concat(name, id) as displaycol
Contatenation is DB specific so you would need to check the exact syntax for your DB.
0 x

azaleas
Ebase User
Posts: 81
Joined: Thu Jul 30, 2015 12:44 pm

#4

Postby azaleas » Tue Nov 03, 2015 7:54 am

Jon, I'm using MySQL and I can't use CONCAT function in Dynamic List. I've tried both Assisted and Native SQL in SQL editor of Dynamic List window. Any ideas? Right now, I'm using the solution with custom list. But it requires additional coding.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#5

Postby Jon » Tue Nov 03, 2015 12:05 pm

MySQL supports the concat function. With assisted SQL, you should have something like this in the Select columns box:

Code: Select all

concat(customer_id, ' ', name) as CUSTOMER_NAME
where customer_id and name are the columns you want to concatenate. Then add a list field named CUSTOMER_NAME.
0 x


Who is online

Users browsing this forum: No registered users and 13 guests