# Conditionally execute filter

**URL:** <https://forum.radzen.com/t/conditionally-execute-filter/1162>\
**Category:** Uncategorized\
**Created:** [May 11, 2019, 7:37am UTC](https://forum.radzen.com/t/conditionally-execute-filter/1162 "2019-05-11T07:37:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgiammarco](https://forum.radzen.com/user_avatar/forum.radzen.com/mgiammarco/32/896_2.png) [@mgiammarco](https://forum.radzen.com/u/mgiammarco)\
**Post date:** [May 11, 2019, 7:37am UTC](https://forum.radzen.com/t/conditionally-execute-filter/1162/1 "2019-05-11T07:37:48Z")

</div>

Hello,  
I have this filter: myfield eq '${security.user.roles[0]}'

But if '${security.user.roles[0]}' eq 'admin' the filter must be skipped because admin can view all records.

I have tried to add in filter '${security.user.roles[0]}'='admin'  
But I get a bad request, how can I do it?  
Thanks,  
Mario

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 11, 2019, 4:21pm UTC](https://forum.radzen.com/t/conditionally-execute-filter/1162/2 "2019-05-11T16:21:08Z")

</div>

Hi Mario,

Maybe you can have two separate invokes with condition if the user is admin or not. The invoke for admins will not have $filter parameter.

Best Regards,  
Vladimir

---

<div class="post-metadata">

**Author:** ![mgiammarco](https://forum.radzen.com/user_avatar/forum.radzen.com/mgiammarco/32/896_2.png) [@mgiammarco](https://forum.radzen.com/u/mgiammarco)\
**Post date:** [July 31, 2020, 7:48pm UTC](https://forum.radzen.com/t/conditionally-execute-filter/1162/3 "2020-07-31T19:48:57Z")

</div>

I need to wake again this thread.  
I have exactly that filter: ${event.filter} AND myRole eq '${security.user.roles[0]}'  
I need to skip the AND part if the user role is "admin".  
I have already three queries if I have to add separate invokes I need to do six queries it begins to be complex.

---

<div class="post-metadata">

**Author:** ![mgiammarco](https://forum.radzen.com/user_avatar/forum.radzen.com/mgiammarco/32/896_2.png) [@mgiammarco](https://forum.radzen.com/u/mgiammarco)\
**Post date:** [July 31, 2020, 8:02pm UTC](https://forum.radzen.com/t/conditionally-execute-filter/1162/4 "2020-07-31T20:02:24Z")

</div>

If I can do ${event.filter} AND '${security.user.roles[0]}' in myRole  
I can remove the admin role and say that an user to be admin has to have all roles.  
But the query above does not work. I do not see errors in the query but I get no results.  
BTW: how can I log all queries sent to DB including parameters? In the past I used tshark but now it does not work anymore. In the documentation I do not find the right way to do it.

---

<div class="post-metadata">

**Author:** ![alistair](https://forum.radzen.com/user_avatar/forum.radzen.com/alistair/32/1011_2.png) [@alistair](https://forum.radzen.com/u/alistair)\
**Post date:** [July 31, 2020, 9:02pm UTC](https://forum.radzen.com/t/conditionally-execute-filter/1162/5 "2020-07-31T21:02:08Z")

</div>

Hi  
I would to keep it simple in the LoadData of the grid create two 'Invoke data source method' and in the Condition have one ${security.user.isInRole("admin")} and the other ${!security.user.isInRole("admin")}

 ![image](https://forum.radzen.com/uploads/default/original/2X/f/fed0d0d4f0ebc0490ec7752dcfaa510a71e4bb78.png)
