Restrict Access to records based on role and/or conditions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2024 05:24 PM
I want to restrict access to records and want the user to only see the records of a particular catalog item if they have a specific role or where he is a 'requested_for' (reference field - sys_user) or opened by (reference field - sys_user) user.
I already have a before query business rule on sc_req_item table to allow access for the users with role 'u_pcategory_user' and now I want to add few more checks and allow visibility for requested_for and opened_by users.
I appreciate any help on this.
condition: !gs.hasRole('u_pcategory_user')
script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2024 06:08 PM
Hi @Community Alums, can you try the below?
current.addEncodedQuery('cat_item=YourCatalogItemSysID^requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
OR
current.addEncodedQuery('cat_item=YourCatalogItemSysID^requested_for=' + gs.getUserID() + '^ORopened_by='+ gs.getUserID());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2024 06:13 PM
Hi @Community Alums below query should help
current.addQuery('cat_item!=a5ac23wd456d9843964b36f0f149ad1a');
var qc=current.addQuery(current.requested_for, gs.getUserID());
qc.addOrCondition(current.opened_by, gs.getUserID());
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 01:43 AM
Hi @Harish KM , @SunilKumar_P
I do not want users without the role 'u_pcategory_user' to access the records of my catalog item. Users with this role should access all the records of the particular item and, the users who doesn't have the role but is opened_by user or requested_for user then they should be able to see the records of theirs, not all the records of the catalog item.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 01:49 AM
Hi @Community Alums then remove the condition and update the script as below
if(!gs.hasRole('u_pcategory_user')
{
current.addQuery('cat_item!=a5ac23wd456d9843964b36f0f149ad1a');
}
else
{
var qc=current.addQuery(current.requested_for, gs.getUserID());
qc.addOrCondition(current.opened_by, gs.getUserID());
}
Harish