Remove selected values from dynamic list

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: Ian, Dave, jcoulson, Jon, Wai

eddparsons
Ebase User
Posts: 41
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Remove selected values from dynamic list

#1

Postby eddparsons » Thu May 02, 2019 10:20 am

I have a dynamic list within a repeater, that allows the user to enter a postcode and select a matching address from the list, as many times as required. Selected addresses are added to an Ebase table. How can I filter the dynamic list to not show addresses that have already been selected? Using Ebase 4.5.4
0 x

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

Re: Remove selected values from dynamic list

#2

Postby Jon » Fri May 03, 2019 8:03 am

One way would be to build the list using script code instead of using a Dynamic List. Then you could check whether the address should be omitted or not.

For example you could build a list from a database table something like this:

Code: Select all

var addresses= [];
var sql = "select address from addresses where post-code = 'xxxxxx'";
services.database.executeSelectStatement(MY_DATABASE_CONNECTION, sql, 
	function (row)
	{
		var addr = row.address;
                // exclude addresses used previously 
                var n = tables.previous_addresses.findRow(tables.previous_addresses.address, addr);
                if (n == -1) {
                  addresses.push(row.address);
                }
	});	

fields.addressesField.createCustomList(addresses);
0 x

eddparsons
Ebase User
Posts: 41
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Re: Remove selected values from dynamic list

#3

Postby eddparsons » Fri May 03, 2019 10:41 am

Thanks Jon but I don't have access to the DatabaseServices class, looks like this was added in 5.2

Any way of doing something similar in 4.5.4?

Regards,
Edd
0 x

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

Re: Remove selected values from dynamic list

#4

Postby Jon » Fri May 03, 2019 1:45 pm

Sorry about that. You could do the same thing using a Database Resource to load a table, or alternatively something like this (this is a more long-winded alternative to services.database that should work with V4.5):

Code: Select all

var con = system.getDatabaseConnection("MY_DATABASE_CONNECTION");
var stmt;
var rs;
var addresses= [];
try
{
  stmt = con.prepareStatement("select address from addresses where post-code = 'xxxxxx'");
  rs = stmt.executeQuery();
  while (rs.next())
  {
      var addr = rs.getString("address");
      // exclude addresses used previously 
      var n = tables.previous_addresses.findRow(tables.previous_addresses.address, addr);
      if (n == -1) {
         addresses.push(row.address);
      }      
   }
}
finally
{
  // it is very important to close any open result sets, statements and connection in this manner
  // otherwise there will be a resource leak.
  if (rs) rs.close();
  if (stmt) stmt.close();
  if (con) con.close();
}
fields.addressesField.createCustomList(addresses);
0 x

eddparsons
Ebase User
Posts: 41
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Re: Remove selected values from dynamic list

#5

Postby eddparsons » Thu May 09, 2019 2:11 pm

Thanks very much Jon, that's perfect.
0 x


Who is online

Users browsing this forum: No registered users and 1 guest