Service catalog user criteria - Not Available For Catalog Items

Ankita9793
Tera Contributor

Hi All,

 

Can someone please suggest why the below criteria's script is not working. 
my requirement is, ABC catalog should not be available/ visible for 'User criteria country' and for users with Job Code 'J04437 or J15505' and having ISO Code as 'MEX'. 

 

Ankita9793_0-1767946418040.png

answer();

function answer() {
    var user = gs.getUserID();

    var grUser = new GlideRecord('sys_user');
    grUser.addQuery('sys_id', user);
    grUser.query();
    if (grUser.next()) {
        var code = grUser.getValue('u_job_code');
        var iso = grUser.getValue('u_iso_code');
       
        if ((code == "J04437" && iso == "MEX") || (code == 'J15505' && iso == "MEX")) {
            return true;
        } else {
            return false;
        }


    }
}
5 REPLIES 5

Ankur Bawiskar
Tera Patron

@Ankita9793 

update as this

-> you were using reverse logic

-> also use user_id in user criteria script as per best practice

-> set answer = true/false in script

-> I couldn't find User Criteria Country field on that table (why you used that)

AnkurBawiskar_0-1767950984271.png

 

Try using below script and uncheck Match All Checkbox

var grUser = new GlideRecord('sys_user');
if (grUser.get(user_id)) {
    var code = grUser.getValue('u_job_code');
    var iso = grUser.getValue('u_iso_code');

    // Hide catalog if: (J04437 OR J15505) AND MEX
    if ((code == "J04437" || code == "J15505") && iso == "MEX") {
        answer = true; // true = HIDE catalog (Not Available For)
    }
}
answer = false; // false = SHOW catalog

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader