User Criteria not working!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:32 AM
Hi Team,
I have build a user criteria to restrict my catalog items for germany users.
So, below is the screenshot of my user criteria
]
When i check for logs, sometimes working and sometimes not and all users are able to view the catalog item.
even though i mapped this user criteria in not availability column.
There is nothing in available column.
Can someone please help me how to fix this?
Thanks,
Sri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:37 AM
Keep return false as last statement in the function and remove from if condition, only keep return true there
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:45 AM
Hi Aman,
Thanks for the response,
I have changed to below code:
gs.log("Inside: All German Users");
answer = checkCondition();
function checkCondition() {
var userGr = new GlideRecord("sys_user");
var curuser = gs.getUserID();
gs.log("current user for user criteria:::" + curuser);
userGr.addQuery('sys_id', curuser);
userGr.query();
if (userGr.next()) {
if (userGr.location.country == 'DE')
return true;
}
return false;
}
But still No luck!
Please help!
Thanks,
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:44 AM
Hi Sri,
Please find the format for the Scripted User Criteria.
/** Scripted User Criteria is not cached, and evaluated everytime, so performance is dependent on the script.
* Populate `answer` with true/false or evaluate to true/false
* The script is evaluated in the scope the user criteria is defined
* Don't use `current` in the script or populate the variable
* Don't use `gs.getUser()` or `gs.getUserID()`,
* instead use `user_id` which contains the user sys_id against whom the evaluation is happening.
*/
Instead of gs.getUserId(), use 'user_id' as per the instructions.
Please mark the answer correct if this answers your question.
Regards,
Tripu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:49 AM
Hi Tripu,
Still no luck!
Thanks,
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 07:02 AM
Hi,
So if location -> country is Germany then you want to block it
How are you determining the country as Germany?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader