Using the Logged-In User ID in WHERE Clauses

In many cases, it’s useful to constrain the result set to records pertaining to the currently logged in user.  For example, in a customer portal application, you may want to display the customer’s recent order history.  Obviously you should display only orders relevant to a particular customer; it would be inappropriate to show every customer’s orders to everyone.  Similarly, you may wish to constrain a sales person’s view to only orders from their accounts.

Select “Logged-in User ID” to constrain the selection criteria to retrieve data for the currently logged in user.

The best way to create such selection criteria is by using the built-in Logged-in User ID function.  To create a table showing only one customer’s orders, you may create selection criteria where one constraint is that the CustomerID must match the Logged-in User ID e.g.:

Order.CustomerID is equal to LoggedInUserID()

Or, you might constrain the data to orders for each sales person, e.g.:

Order.SalesRepID is equal to Logged-in User ID

The currently logged in user ID value provided comes from the application security code generated by Iron Speed Designer.  This code maintains the user ID and other state information throughout your application.  More information on the application security mechanism generated by Iron Speed Designer is in “Securing Your Web Pages with Role-Based Security”.

See Also

Customizing Database Queries with the Query Wizard

Using Tables and Views in WHERE Clauses

Using Constant Values in WHERE Clauses

Using URL Parameters in WHERE Clauses

Using the Logged-In User ID in WHERE Clauses

Calling Custom Code Functions in WHERE Clauses

Adding a Custom Query