Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Service catalog user criteria - Not Available For Catalog Items

Not applicable

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;
        }


    }
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Community Alums 

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! 🙏

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron

@Community Alums 

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! 🙏