Solved

current user

  • 30 October 2020
  • 1 reply
  • 94 views

Userlevel 3
Badge +5

I want to filter records based on the user that is currently logged into the application.

This should be possible as there are a lot of prefilters for My Projects and such, but can't seem to find out how to do this.

So how do I know what the current user is? And how do I use this in prefilters and views?

icon

Best answer by Mark Jongeling 30 October 2020, 12:44

View original

This topic has been closed for comments

1 reply

Userlevel 7
Badge +23

Hi Roy,

In the project I work on we use the function dbo.tsf_user(). This will return the current user his login name. If you would save these login names inside an employee table for example, you can use this inside your application for a variety of things, such as filtering records.

More on it here: https://docs.thinkwisesoftware.com/docs/kb/username.html

You can then use it in code to retrieve the unique employee id to use in other areas inside your application. Example code:

select p.project_name
from project p
where exists (select 1
from employee e
where e.employee_id = p.project_leader_id
and e.login_name = dbo.tsf_user()
)

This would then retrieve all project names where the project leader is the logged in user. 

Hope this helps you out!

Kind regards,
Mark Jongeling