Help with User Criteria - Not Available For - Advanced Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 08:41 AM
Hello - I am having trouble getting an advanced script in a User Criteria record working properly. We have a 'Temp Accounts' User Criteria that we are using in some of our 'Not Available For' criteria for catalog items. However, we have one specific location that we want to exclude from this. This is what I am using:
checkCondition();
function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(user_id);
if (user.location != '123' && user.u_ad_temp_account == 1) {
return true;
}
return false;
}
The original script was the same, except for this line:
if (user.u_ad_temp_account == 1) {
I have validated that my test user is a part of location 123 and is flagged as a Temp Account, however it never lets that test user view the catalog item. It is always evaluating to 'true' in this user criteria record. I am wondering if I am able to use the != logic in a script like this, or if I am missing something.
Thanks!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 08:52 AM
Try setting the value of "answer":
answer = checkCondition();
function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(user_id);
if (user.location != '123' && user.u_ad_temp_account == 1) {
return true;
}
return false;
}
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 10:53 AM
Thank you for the quick response! Unfortunately, this isn't working either. It has always worked, and I can get it to work just fine if I don't include the 'user.location != '123'. It is 'technically' working, but it is ignoring the user.location != '123' part.
If I have a user that is flagged as a temp account and they are in location 123, they are still triggering the 'return true' part of the script.
With this same script in place (the initial one I posted with the location != '123'), I opened one of our users that was flagged as a Temp Account and unchecked that value, and then they were able to see it right away. It is like it is not recognizing the != on the location value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 11:10 AM
I was able to get it sorted, needed to use the sys_id or DisplayValue for that location value in the script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 11:16 AM
Sorry about that, I assumed "123" was just a place holder!
Michael D. Jones
Proud member of the GlideFast Consulting Team!