Nested find() and search()

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

 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.

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?

Yes you can say that based on lookup need to narrow the the resultset.

Ok, in that case your in luck.

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

foundset.find();
<somecode>
if (foundset.search()) {
   <do some action>
   foundset.find();
   <some more code>
   search(false, true)
}

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=
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=
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().

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?

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.