Restricting user to view incident

hydu9535
Tera Contributor

Hi All

 

I have a requirement where i have written a before query BR,

I have 3 roles

It_user , pay_user and admin

 

i need to show ticket type = it if i have it_user role

and ticket type = pay_user if i have pay_user role

 

but when i have it_user and pay_user i need to see both the inc's

2 REPLIES 2

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Can you show what you have done so far? The Script and result. What is not working 

-Anurag

Pratiksha2
Mega Sage

Hello @hydu9535 -
Please try using below code: 

(function executeBeforeQuery(current, previous /*query*/) {
    // Get current user's roles
    var userRoles = gs.getUser().getRoles();

    // If the user has the IT User role
    if (userRoles.indexOf('it_user') != -1) {
        // Modify the query to only fetch tickets with type 'IT'
        current.addQuery('ticket_type', '=', 'it');
    }
    // If the user has the Pay User role
    else if (userRoles.indexOf('pay_user') != -1) {
        // Modify the query to only fetch tickets with type 'Pay'
        current.addQuery('ticket_type', '=', 'pay');
    }
    else {
         current.addQuery('');
    }

})(current, previous);

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Pratiksha