- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 09:50 AM
I set up a User Criteria that includes users of a particular role.
Then I went into a catalog item and in the Available For I added the User Criteria that I created above. Now, everyone can see it. ServiceNow, for the love of all that is holy, what is the point of doing nonsense this when it doesn't work?
So now I'm left with adding a Not Available For where I will make it unavailable for:
1. Users with ITIL roles (easy to set up)
2. Users without roles - I create a new user criteria and check advanced. In the code box, I've tried number of different versions of this, but I get this error ("JavaScript parse error at line (2) column (6) problem = invalid return"), so can I get some help?
if(!gs.getUser().hasRoles()){
return true;
} else{
return false;
}
Please, ServiceNow, in the name of all that is holy, explain to me why you would bother replacing something that did work with something that doesn't. How does that serve anyone, especially ServiceNow?
When I envision the developers at ServiceNow, I see a bunch of people wearing only black, studded leather carrying whips. It must be the dress code there, correct?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 03:29 PM
Created a new user criteria called, "User with no roles"
checked advanced
added the following to the script:
if(!user.HasRoles()) {
condition =false;
}
Added that user criteria to the catalog item's not available for:
Long story short, indicating which user criteria to use to share a catalog item with isn't enough.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 03:29 PM
Created a new user criteria called, "User with no roles"
checked advanced
added the following to the script:
if(!user.HasRoles()) {
condition =false;
}
Added that user criteria to the catalog item's not available for:
Long story short, indicating which user criteria to use to share a catalog item with isn't enough.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 11:07 PM
Hai Eric Wills Thanks a lot for your script it saved me a lot 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2017 09:14 AM
Hi Eric,
I am struggling greatly with my user criteria. I have scripted an available for user's in a particular country. Every now and then it seems to work and then it stops working. So are you telling me along with my Available for I also have to have a NOT available for setup? Here is my script for the available for, do I have to make an opposite for the not available for?
var answer = '';
if (gs.getUser().getRecord().getDisplayValue('country') == "BE" || "Belgium" || "AE" || "United Arab Emirates" || "NL" || "Netherlands" || "France" || "FR" || "AT" || "Austria" || "DE" || "Germany" || "CH" || "Switzerland"){
answer = true;
}
else{
answer = false;
}
Thank you in advance.
Stacy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2017 10:02 AM
Stacy,
Maybe try something like this.
Set the value you want to get = to a variable, and then (with the gs.log), this will write to the log, so you can see what the value of country is.
I commented (started the line with "//") the line of code you wrote to check on the value for country and replaced it with checking the new variable aCountry, where the variable is checked against each value to see if there is a match. There are less cumbersome was to do this, I'm sure.
Also, doesn't the system have a pick list for the country? Instead of BE and Belgium, I would think that it would be one or the other.
var answer = '';
var aCountry = gs.getUser().getRecord().getDisplayValue('country');
gs.log ('Stacy: This is the users country: ' + aCountry);
//if (gs.getUser().getRecord().getDisplayValue('country') == "BE" || "Belgium" || "AE" || "United Arab Emirates" || "NL" || "Netherlands" || "France" || "FR" || "AT" || "Austria" || "DE" || "Germany" || "CH" || "Switzerland"){
if (aCountry == "BE" || aCountry == "Belgium"|| aCountry == "AE"|| aCountry == "United Arab Emirates"|| aCountry == "NL"|| aCountry == "Netherlands"|| aCountry == "France"|| aCountry == "Netherlands"|| aCountry == "FR"|| aCountry == "AT"|| aCountry == "Austria"|| aCountry == "DE"|| aCountry == "Germany"|| aCountry == "CH"|| aCountry == "Switzerland"){
answer = true;
}
else{
answer = false;
}