Need help with User Criteria script

Service now11
Tera Contributor

Hi,

 

I'm trying to set up a User Criteria script for a catalog item that allows users with the employee number "192" to view the catalog item. Users with any other employee number should not be able to view the item. Below is my script, but I'm not getting the desired output. Can anyone help me troubleshoot?

 

(function() {
    var userId = gs.getUserID();
    var gr = new GlideRecord('sys_user');
    if (gr.get(userId)) {
        var employeeNumber = gr.getValue('employee_number'); 
          if (employeeNumber == '192') {
            return true;
        }
    }
         return false;
})();
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Service now11 

try this

    var userId = user_id;
    var gr = new GlideRecord('sys_user');
    if (gr.get(userId)) {
        var employeeNumber = gr.getValue('employee_number');
        if (employeeNumber == '192') {
            answer = true;
        } else
            answer = false;
    }

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Service now11 

try this

    var userId = user_id;
    var gr = new GlideRecord('sys_user');
    if (gr.get(userId)) {
        var employeeNumber = gr.getValue('employee_number');
        if (employeeNumber == '192') {
            answer = true;
        } else
            answer = false;
    }

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Service now11
Tera Contributor

Thank you @Ankur Bawiskar . It's working.