Filter records by logged user in sql dataset

Hi all,
inside the application I have report that is using sql data set like this for example:

select o.order_number,c.customer_name,su.user_name
from orders o
join customers c on o.customer_id=c.id
join sec_user su on c.user_id=su.id

My goal is to display only the records created by the current user, logged in the application. Obviously I have to add filter in the sec_user table, but my question is how could I get the current user and use it in the sql query? Is this even possible only with sql ?

Thanks!

Hello @stefanov.dls,

You need to use the groovy script to get the current user.

Groovy:

import com.haulmont.cuba.core.global.AppBeans
import com.haulmont.cuba.core.global.UserSessionSource

def user = AppBeans.get(UserSessionSource.class).getUserSession().getUser()

return [["name" : user.name]]

You cannot get the current user using only SQL.

Regards,
Nikita