- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:27 AM
Hello Team,
I am currently trying to hide a catalog item based on the title of the logged in user and have added Not Available for User criteria and below it the script.
But it seems to be not working
(function() {
var rec = new GlideRecord("sys_user");
rec.addEncodedQuery("sys_idSTARTSWITH"+user_id+"^titleLIKEContractor");
rec.query();
if(rec.next()){
return false;
}else{
return true;
}
})();
please can anyone let me know how can we achieve this
Thank you very much in advance
Thank you
Prajwal
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:46 AM
@Prajwal G Vaish Check if the query returns correct response by using gs.info logs. If it returns the correct result and still the catalog item is visible then use cache.do to clear the cache.
Here is a support article on the caching of user criteria https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0790108.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:29 AM
Try replacing
rec.addEncodedQuery("sys_idSTARTSWITH"+user_id+"^titleLIKEContractor");
with
rec.addEncodedQuery("titleLIKEContractor");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:33 AM
Hi @AnirudhKumar ,
Thank you very much for the response
Tried what you have mentioned but the result is still the same

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:33 AM - edited ‎08-22-2024 08:35 AM
@Prajwal G Vaish Can you update the script as follows and see if it works. Basically the answer variable needs to be set instead of returning true/false.
(function() {
var rec = new GlideRecord("sys_user");
rec.addEncodedQuery("sys_idSTARTSWITH"+user_id+"^titleLIKEContractor");
rec.query();
if(rec.next()){
answer = false;
}else{
answer = true;
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:41 AM
Hi @Sandeep Rajput ,
Thank you very much for the response
Tried what you have mentioned but the result is still the same