Restricting user to view incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 04:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 04:23 AM
Hi,
Can you show what you have done so far? The Script and result. What is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 04:44 AM
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