User Criteria in the catalog item

2022_ServiceNow
Tera Expert

Hi All,

 

In the user criteria for catalog item, I have the make the catalog item available only for the users depending upon their Department and Business Unit. If their Department and BU contains IT then it should be available. How can I make this?

 

Thanks in advance!

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi,

You need to check for Department & Business unit of logged in user & can be something as below

answer = checkCondition();

function checkCondition() {

    var user = new GlideRecord('sys_user');
    user.addQuery('sys_id', gs.getUserID());
    user.addEncodedQuery('department.nameLIKEIT^ORu_business_unit.nameLIKEIT'); //Replace Business unit & Deparment dicitonary name value accordingly
    user.query();
    if (user.next()) {
        return true;
    } else {
        return false;
    }


}

View solution in original post

2 REPLIES 2

PA001
Mega Sage

Hello,

 

Add logic in the user criteria script section as per your business logic .

PA001_0-1684126297841.png

Please mark my response as Correct / Helpful

Thanks

Jaspal Singh
Mega Patron
Mega Patron

Hi,

You need to check for Department & Business unit of logged in user & can be something as below

answer = checkCondition();

function checkCondition() {

    var user = new GlideRecord('sys_user');
    user.addQuery('sys_id', gs.getUserID());
    user.addEncodedQuery('department.nameLIKEIT^ORu_business_unit.nameLIKEIT'); //Replace Business unit & Deparment dicitonary name value accordingly
    user.query();
    if (user.next()) {
        return true;
    } else {
        return false;
    }


}