set the user criteria of a catalog item

NiloferS
Tera Contributor

NiloferS_0-1718801472385.png

I have written the above script in 'Available for" related list in a catalog item, so that catalog will be visible only gor internal users. But its not working as expected. Kindly suggest.

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Try this

var user = GlideUser.getUserByID(user_id);
if (user.u_type_of_user == 'Internal') {
    answer = true;
} else {
    answer = false;
}
-Anurag

Zach Koch
Giga Sage
Giga Sage

Couple things I wanted to note and verify. Is your Value of "Internal" correct?  Are you sure that is the exact value? You should verify also that what you are getting as a value to compare against In addition, if you are having problems testing it, this may be your issue. You should not be using gs.getUser() in User Criteria as it can cause issues in testing. Here is a link to the Docs page and a screenshot of the relevant info to explain why.

User criteria docs 

ZachKoch_0-1718802072202.png

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Akshay03
Kilo Sage

Hi @NiloferS ,

You can use this script

 

var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', user_id);
gr.addQuery('u_type_of_user', 'Internal');
gr.query();

return gr.next();

 

You have not considered the logged in user. 

The query is not right.

-Anurag