Catalog Item Visibility

Prajwal G Vaish
Giga Guru

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

1 ACCEPTED SOLUTION

@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.

View solution in original post

9 REPLIES 9

AnirudhKumar
Mega Sage
Mega Sage

Try replacing

rec.addEncodedQuery("sys_idSTARTSWITH"+user_id+"^titleLIKEContractor");

 with

rec.addEncodedQuery("titleLIKEContractor");

Hi @AnirudhKumar ,
Thank you very much for the response

Tried what you have mentioned but the result is still the same

Sandeep Rajput
Tera Patron
Tera Patron

@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;
    }
 
})();

 

Hi @Sandeep Rajput ,
Thank you very much for the response

Tried what you have mentioned but the result is still the same