Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Filter table content depending on current user

Issue

I need to filter a data table in my Appsmith application to only show sales data related to my user account's branch, so that I cannot see other branch sales. I have linked the application to a SQL Server data source containing all company sales and have successfully retrieved the current user's email information. However, I am unsure how to use this information to filter the data table by both the user's email and the InvWh column. I need help with incorporating this logic into my SQL query.

Resolution

To filter data in an Appsmith application based on the current user's email, access the user's email using {{ appsmith.user.email }}. Then, include this email in the SQL query that fetches the relevant data by adding a WHERE clause that filters by the email column.

For example, the SQL query may look like:

SELECT * FROM invoices WHERE email = {{ appsmith.user.email }} AND InvWh = 'BranchA'

This will retrieve all invoices that match the current user's email and are associated with BranchA.

To incorporate this query into the Appsmith application, add it as the query for the relevant data table or widget. The filtered data will then display based on the current user's email.

Note that this example assumes that the email column in the SQL table matches the email associated with the current user in the Appsmith application. If not, adjust the WHERE clause to match the proper column and user information.