find()

Questions, tips and tricks and techniques for scripting in Servoy

find()

Postby jos@devoon.nl » Thu Oct 24, 2013 2:43 pm

when you work with foundsets you often deal with find().
According to the documentation one can use an array of values to use the 'IN' statement.
Like:
foundset.user_id = [222,534,464]
works fine.

The opposite, i.e. 'NOT IN' is not possible, or I can't find the right syntax for it?

foundset.user_id = ![545,687,876] -> does not work

So I use a query -> loadrecords(query) instead. Or is there another way?
Jos Uitenbogaard
Devoon
User avatar
jos@devoon.nl
 
Posts: 60
Joined: Tue Oct 25, 2011 11:59 am
Location: Reeuwijk NL

Re: find()

Postby sovanm » Thu Oct 24, 2013 3:13 pm

Hi Jos,

I was in the same confusion few days back, on which i had two options to achieve. I am sharing those below. I used the second one because first one might take a bit more time as it had to do a search and then invert the foundset.

You can do this to achieve the result
Code: Select all
if(foundset.find()) {

     foundset.user_id = [545,687,876];
     foundset.search();
     foundset.invertRecords();
}


Or you can use the query object as

Code: Select all
      // Create the query
      /**@type {QBSelect<db:/server/users>}*/
      var QBSelectObj = databaseManager.createSelect('db:/server/users');
      
      // Build the filtration statement
      QBSelectObj.where
         .add(QBSelectObj
            .not(QBSelectObj.columns.user_id.isin([545,687,876])));
      
      // Load the foundset
      foundset.loadRecords(QBSelectObj);


I am also not sure if these is the best way or not. If some better ways are available please do share.
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India

Re: find()

Postby jos@devoon.nl » Thu Oct 24, 2013 3:49 pm

Hi Sovan,

I did not think about the first option. but it might work, but when there are more then one search criteria it gets complicated (-:

I use indeed the second one like you (with query's)
Jos Uitenbogaard
Devoon
User avatar
jos@devoon.nl
 
Posts: 60
Joined: Tue Oct 25, 2011 11:59 am
Location: Reeuwijk NL


Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests