Using ew_IIF in Table Filter

Tips submitted by ASPMaker users

Using ew_IIF in Table Filter

Postby JAW » Sat Jan 21, 2012 11:01 pm

Hi All,

I have been working on a project that compels me to use some interesting trickery to get security to work properly. I have tables that I want people to see data on that is not their data depending on User Level. So here is the scenario.

For the purpose of this example I will use Employee as User Level 1 and Managers as User Level 2. Obviously Administrators can always see everything. I used UserID as the User Id Field in the Security tab in ASPM. I did not assign UserID to any of the tables. If I would have done that it would have prevented anyone who does not own the data from viewing it. I needed the Managers to have the ability to see anyone and everyone's data in the tables, but I wanted the Employees to only see their own. All the Permissions are still set in the User Levels Permissions table, no change there. I also needed to filter the data in the table by a particular field value.

I set up dynamic user levels per the instructions. What I want for these user Levels is;

User Level Administrator - Can see, add, edit and delete all data with no filtering.
User Level 1 - Can add data, edit data, view data but only the data they enter. The data is filtered by another field I will call DataType.
User Level 2 - Can view data no matter who enters it. The data is filtered by the same field as above.

Now, in the table filter I use the ew_IIF Statement to filter how I want them to see things. Here is an example of that filter.

"ew_IIF(CurrentUserLevel=-1, "", ew_IIF(CurrentUserLevel=1, "[UserID]=" & CurrentUserID & " AND [DataType]='My Data Type Here'", "[DataType]='My Data Type Here'"))"

In the above example I am nesting two ew_IIF Statements together. So, what the above does is to use no filter if the Administrator is viewing the data, it displays the data by CurrentUserLevel and DataType if the CurrentUserLevel is 1 and it only filters by DataType for all other user levels. So the Managers can see all the data in the table, Employees can see, add and edit their own data only and Administrators have full permissions.

I have seen questions in the forum that ask about things like this and thought I would send this along for a hint. ew_IIF is a powerful tool when used properly and can be used in field level filtering as well as table level filtering. I hope this helps someone, it sure helped me.

Happy coding.
JW
JAW
 

Return to User Submitted Tips (ASPMaker)