# Advanced search

**URL:** <https://forum.servoy.com/t/advanced-search/10611>\
**Category:** Classic Servoy\
**Created:** [May 6, 2009, 7:08am UTC](https://forum.servoy.com/t/advanced-search/10611 "2009-05-06T07:08:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maservoy](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@maservoy](https://forum.servoy.com/u/maservoy)\
**Post date:** [May 6, 2009, 7:08am UTC](https://forum.servoy.com/t/advanced-search/10611/1 "2009-05-06T07:08:50Z")

</div>

I am trying to make “advanced searchs” on Servoy, using two related forms: a container form and a related form (tabPanel).

I start a find() and I introduce my criteria on the first record of the container;  
then I create a new record, and I introduce new criteria, so I get a condition such as (criteria1 OR criteria2)  
Let’s say it’s a query such as:  
select \* from container\_table  
where (container\_table.criteria1 OR container\_table.criteria2)

Now, let’s say I introduce search criteria not only on the container form but also on the related form.  
Then the query I would get would be this one:  
select \* from container\_table  
join related\_table on container\_to\_relatedTable\_relation  
where (container\_table.criteria1 OR container\_table.criteria2)  
AND (related\_table.criteria)

But this is not what I want.  
I would like a query such as  
select \* from container\_table  
join related\_table on container\_to\_relatedTable\_relation  
where (container\_table.criteria1 AND related\_table.criteria1)  
OR (container\_table.criteria2 AND related\_table.criteria2)

I know that this is NOT the way Servoy works, because the relation between the container form and the relatedTable has no effect on my search.  
But is there a way to bypass this behaviour to make the query behave the way I want?

Thanks a lot,  
Miguel.-

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [May 6, 2009, 9:55am UTC](https://forum.servoy.com/t/advanced-search/10611/2 "2009-05-06T09:55:00Z")

</div>

Hi Miguel,

> maservoy:  
> Now, let’s say I introduce search criteria not only on the container form but also on the related form.  
> Then the query I would get would be this one:  
> select \* from container\_table  
> join related\_table on container\_to\_relatedTable\_relation  
> where (container\_table.criteria1 OR container\_table.criteria2)  
> AND (related\_table.criteria)

I would actually consider this a bug in the Servoy parser. When you add criteria in a related table you are doing that in the context of the **selected** main record, not all main records. I suggest you file this as a bug in [Servoy’s support system](http://www.servoy.com/s).

> maservoy:  
> But is there a way to bypass this behaviour to make the query behave the way I want?

The only workaround I know of is to create the SQL yourself and load the records using controller.loadRecords(SQL) or controller.loadRecords(SQL, parameterArray).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [May 6, 2009, 10:28am UTC](https://forum.servoy.com/t/advanced-search/10611/3 "2009-05-06T10:28:58Z")

</div>

I’m not sure if this is going to help, but did you try: controller.duplicateRecord() instead of controller.newRecord() inside the

if(controller.find() ) {  
//your search here…  
}

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [May 6, 2009, 10:44am UTC](https://forum.servoy.com/t/advanced-search/10611/4 "2009-05-06T10:44:32Z")

</div>

Hi,

Which version of Servoy is this ?

Regards,

Hans

---

<div class="post-metadata">

**Author:** ![maservoy](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@maservoy](https://forum.servoy.com/u/maservoy)\
**Post date:** [May 6, 2009, 3:39pm UTC](https://forum.servoy.com/t/advanced-search/10611/5 "2009-05-06T15:39:43Z")

</div>

> ROCLASI:  
> I would actually consider this a bug in the Servoy parser. When you add criteria in a related table you are doing that in the context of the **selected** main record, not all main records. I suggest you file this as a bug in [Servoy’s support system](http://www.servoy.com/s).

Hi Robert,  
it’s not a bug. I suggested it and the answer was that Servoy behaves in that way.  
Nevertheless you gave me an idea on trying to join both tables using the parameters and then loadRecords…

> Harjo:  
> I’m not sure if this is going to help, but did you try: controller.duplicateRecord() instead of controller.newRecord() inside the  
> if(controller.find() ) {  
> //your search here…  
> }

Hello Harjo,  
I already tried. It’s the same behaviour…

> Hans Nieuwenhuis:  
> Hi,  
> Which version of Servoy is this ?  
> Regards,  
> Hans

Hi Hans,  
it’s Servoy 3.5.9

Regards and thanks…

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [May 6, 2009, 6:15pm UTC](https://forum.servoy.com/t/advanced-search/10611/6 "2009-05-06T18:15:56Z")

</div>

Hi Miguel,

> maservoy:  
> it’s not a bug. I suggested it and the answer was that Servoy behaves in that way.

Maybe not a bug then but in my view a flawed design. Putting criteria in related tables should be in only the context of the parent record.  
I will file a case for this.

---

<div class="post-metadata">

**Author:** ![maservoy](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@maservoy](https://forum.servoy.com/u/maservoy)\
**Post date:** [May 8, 2009, 7:59am UTC](https://forum.servoy.com/t/advanced-search/10611/7 "2009-05-08T07:59:21Z")

</div>

> ROCLASI:  
> Hi Miguel,  
> Maybe not a bug then but in my view a flawed design. Putting criteria in related tables should be in only the context of the parent record.  
> I will file a case for this.

I agree. It’s very difficult for a user to understand that behaviour.  
I am tring to solve it with our callbacks.

We have a global method for every onLoad, onHide, onRecordSelection… and every form makes a call to this global method.  
The global method looks for a local method on the calling form (also named onLoad, onHide…) etc. and if it exists, it fires the local one.  
Somehow, these callbacks are our application architecture; and I’m trying to figure out something in these callbacks to bypass Servoy’s behaviour.

Thanks and regards,
