
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2019 11:41 AM
Hello, I have an advanced user criteria that is set up to restrict certain users from seeing a catalog item in the Service Catalog.
Here's the script:
var company = gs.getUser().getCompanyID();
if(!gs.hasRole('itil') && company == "TEST"); {
answer = false;
}
What I can't get to work is the user role portion. I've tried (!gs.getUser().hasRole('itil') and that still doesn't work.
There are users in "TEST" company that have ITIL role, and they need to be able to view the catalog item. How can I restrict this to non-itil TEST company users?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 05:19 PM
Also you need to either wrap the other answer statement (answer = false) in an else statement or place it above the if statement as it is going to always return false.
var company = gs.getUser().getCompanyID();
if(!gs.hasRole('itil') && company == 'TEST'){
answer = true;
}else{
answer = false;
}
or
answer = false;
var company = gs.getUser().getCompanyID();
if(!gs.hasRole('itil') && company == 'TEST'){
answer = true;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2019 01:24 PM
I changed the company to the sys_id of the company I needed.
I impersonated two separate users in the TEST company, one with ITIL role, and one with NO roles.
Both users are unable to view the catalog item. I need the ITIL user to be able to view it still. It is ignoring the first half of the script: !gs.hasRole('itil')

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2019 02:27 PM
Can you add else condition and try again
var company = gs.getUser().getCompanyID();
if(!gs.hasRole('itil') && company == "TEST"); {// in 'TEST' you should pass the sys_id of the company
answer = true;
}
answer = false;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 06:43 AM
I added the else answer = false; as you suggested, and now the reverse is happening, every user in TEST company can see the catalog item. I'm unsure what's going on with this, it looks correct, but it's not working.
Is the following a valid syntax for user does NOT have itil role?
if(!gs.hasRole('itil')
This is the only piece that isn't parsing correctly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 07:08 AM
Can you add parenthesis to gs.hasRole
if( (!gs.hasRole('itil')) && company == "TEST")

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 07:14 AM