Nested find() and search()

Questions, tips and tricks and techniques for scripting in Servoy

Nested find() and search()

Postby hardina09 » Tue Jun 26, 2012 7:53 pm

I need to work with foundset.find() wherein I need to do lookups in database and get he result. Based on the result I need to again relook up the database table and perform some actions.
for example: In my formA I am having Start button. When clicked need to check empID is in table by using
Code: Select all
foundset.find()
<somecode>
if(foundset.search())
<do some action>

if foundset.search() returns true, I need to lookup for the empID which department id belongs to. and then lookup for the category for that department. So on

In short for every stage I need to look for some information in table, based on information available need to perform actions and need to relook up table for the information.

Requires suggestions as early as possible.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: Nested find() and search()

Postby omar » Wed Jun 27, 2012 10:31 am

Are you saying that when you do your first lookup and a result is found you want to narrow down the resultset to less records?
Intrasoft, Founder
Omar van Galen
omar@intrasoft.nl
+31-(0)6-21234586
Servoy Developer
omar
 
Posts: 340
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands

Re: Nested find() and search()

Postby hardina09 » Wed Jun 27, 2012 2:18 pm

Yes you can say that based on lookup need to narrow the the resultset.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: Nested find() and search()

Postby omar » Wed Jun 27, 2012 2:54 pm

Ok, in that case your in luck.

The search() has two optional parameters: clearLastResult and reduceSearch. So what you want to do is:

Code: Select all
foundset.find();
<somecode>
if (foundset.search()) {
   <do some action>
   foundset.find();
   <some more code>
   search(false, true)
}
Intrasoft, Founder
Omar van Galen
omar@intrasoft.nl
+31-(0)6-21234586
Servoy Developer
omar
 
Posts: 340
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands

Re: Nested find() and search()

Postby hardina09 » Wed Jun 27, 2012 5:09 pm

Got you Omar. I have created test form trying to work with above code. Below is code which is not executing in exact flow

foundset.find()
foundset.empid=<somevalue>
if(foundset.search(true,false)) //found the empid, will execute the if part
{
foundset.find() //finds the deptnm wherein emp is working
foundset.dept_nm=<somevalue>
if(foundset.search(true,false) // found the deptnm for that empid will execute if part
//do someaction;
else // if no deptnm is found for found empid, will perform some other actions.
//do some action;
}
else //if empid is not found
//do some action

Somehow, even if deptnm does not match with the foundset.detpt_nm. It does not execute else part . In other word flow of if - else is not working properly.
Do you have any idea how flow works in nested find() and search().
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: Nested find() and search()

Postby omar » Wed Jun 27, 2012 6:18 pm

I am not quite sure what it is that you trying to achieve. Are you talking about one form with one foundset (which is naturally based on 1 table) or multiple forms with different tables in their foundset?
Intrasoft, Founder
Omar van Galen
omar@intrasoft.nl
+31-(0)6-21234586
Servoy Developer
omar
 
Posts: 340
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands

Re: Nested find() and search()

Postby hardina09 » Wed Jun 27, 2012 7:37 pm

It is based on one form with one foundset. Anyways, I got what I want in my application Previously if-else flow was not working properly. Reason-need to add correct parameter to search() at the correct time, that its.

Anyways, great help. Omar
Thanks.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests