Select record from group data source based on logged in user

I have an Entity named Files with attributes file_name and shared_with, shared_with is a many to many association of an Entity named Department.

When a user shares a file, they add more than one Department to share_with attribute, thus a single shared file can have many Departments.

Let us say i have two users, user1 in Department1 and user2 in Department2, how can a achieve that when user1 logs in and opens the Files browser can only see files which include Department1 in shared_with attribute.

The Files browser uses a grouped datasource

Thank you

Hey,
I believe you searching for Constraints

In your case it would be like that:

Read constraint for app$Files and condition:
join:

join {E}.shared_with sharedDepartments 
join app$Departmet userDepartment
join userDepartment.user user on (user.id = :session$userId)

and where

userDepartment.id in sharedDepartments 

Without data model knowledge it looks clumsy but i believe you can see direction

1 Like

I tried to implement the above code in my project but i failed,

Here is how my project is

I have Entities Myfiles , SharedFiles, Employee, Department

Myfiles has file name and shared_with attributes, shared_with is a many-many association with Department. Department has name and user attribute, user is a one-many Association with Employee. Employee has user (Association of user) and department attribute, department is a many-one Association with Department.

SharedFiles, has file attribute which is a one-one Association with Myfiles.

Regards

So it probably would look like this

left join {E}.shared_with sharedDeps
left join mypr$Employee empl
left join empl.user usr on usr.id = :session$userId
left join empl.department userDep
sharedDeps.id = userDep.id

But you really should just experiment for a while with your constraint.

Thank you,

I will surely experiment