Catalog item Available For user criteria

somujit
Tera Contributor

Hello Experts,

I have a requirement to make catalog item available from portal, if logged in user has role 'itil' and belong to a specific business name (which is defined through a custom string type field in user table)

 

I have defined the catalog item Available for as below, however it still displays for any logged in user

somujit_0-1721965942579.png

Script:

getBizValue();
function getBizValue() {
    var userID = gs.getUserID();
    var userRec = new GlideRecord('sys_user');
    userRec.get(userID);
    if(userRec.u_business=='Digital Solutions' && userRec.active == 'true' ) {
       answer= true;
    }
else
{
 answer=false;
}
}
 
Can you please advise what I am doing wrong here and how to fix this issue?
 
Thanks and Regards,
Somujit
7 REPLIES 7

So did you add debugging in the user criteria? To see if it is triggered at all? If the if condition is reached? Etcetera?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi,

While running the script using 'user_id', it show the error as mentioned above in debugger.

While running the script using the gs.getUserID(), it returns the logged in user sys_id. but fails enter the if condition.

 

Can you let me know on the debugging steps to identify the exact issue? I usually used the log/info messages to debug.

I'm not talking about any debugger, you already tested the basic code in background script so that's fine. Now just test the User Criteria how you would normally run it, add debugging in the script itself, for example that in system log you can see the result, etc..

 

Debugging your script will show the issue within a few seconds.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn