Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Restricting user to view incident

mohammedhyd
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

Hi,

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

-Anurag

Pratiksha2
Mega Sage

Hello @mohammedhyd -
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