Restrict Access to records based on role and/or conditions

Community Alums
Not applicable

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

(function executeRule(current, previous /*null when async*/ ) {
    current.addQuery('cat_item!=a5ac23wd456d9843964b36f0f149ad1a');
})(current, previous);


 

 

11 REPLIES 11

SunilKumar_P
Giga Sage

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());

Harish KM
Kilo Patron
Kilo Patron

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());

Regards
Harish

Community Alums
Not applicable

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.

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());

}

Regards
Harish