- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2018 06:45 AM
I'm trying to utilize the User Criteria Loader API to identify the User Criteria associated with a particular user.
https://developer.servicenow.com/app.do#!/api_doc?v=london&id=UCLS-getAllUserCriteria
I am able to use the function "getAllUserCriteria(String userId)" and provide the sys_id of the user I am interested in. This returns an array of sys_ids of the user criteria records that match. The problem I am having is that for all our User Criteria which use scripts (advanced = true), when the UserCritieria Loader function is called, the script within the user criteria always runs based on the logged in user, not the one provided in the function parameter. I figure this is because in our user criteria script, we use `var userid = gs.getUserID();` and then determine based on that user if the result is true or false.
Does anyone know how to use the UserCriteriaLoader API with User Criteria that uses advanced scripts? Is there a way from within the User Criteria script, to identify the user being looked at without using gs.getUserID()?
Here is a simplified example. Given the below User Criteria Script, if I call getAllUserCriteria('87f606c7db11230049027dda8c9619de') (where I provide a user's sys_id), I would expect the returning array to include this User Criteria. However, when I test this in my personal dev (OOB London), this user criteria is only included in the resulting array if I am logged in as that particular user.
var userid = gs.getUserID();
if (userid == '87f606c7db11230049027dda8c9619de')
answer = true;
else
answer = false;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2019 11:53 PM
In user criteria script, you can user variable user_id instead of gs.getUserID(). It is probably passed from some upper function.
I tried it on Madrid version and it works. It holds user id, which is provided via UserCriteriaLoader.
I has less impact than storing it in user session, but as it is not officially documented, I am not sure, how reliable this will be in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 04:19 AM
Hi Ankur,
Unfortunately we didn't use this solution on New York version. We will be migrating this solution in the beginning next year to New York. If we will have some solution, I will let you know.
Best Regards,
Jakub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 04:32 AM
Hi Ankur,
I just tried it on "glide-newyork-06-26-2019__patch2-09-18-2019".
In user criteria script I have:
gs.log('user_id ' + user_id, 'Testing');
And calling it from the background script:
var result = new SNC.UserCriteriaLoader.getAllUserCriteria('62826bf03710200044e0bfc8bcbe5df1');
gs.info(result);
And in the log I can see:
Testing: user_id 62826bf03710200044e0bfc8bcbe5df1
So everything seems working. User id, which is passed to the constructor is logged. Just be aware, that user criteria are cached, so you need to run cache.do, when you change something.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 08:41 PM
Just wanted to say thanks Jakub on the last note you added here about clearing the cache. I was having an issue with a client not being able to view a form even though they matched the user criteria. It solved my issue by running cache.do and I would have taken a lot longer to resolve the issue by doing this simple thing.