advance reference qualifier

si21
Tera Guru

Hi team,

I have a variable 'Employee' which is a reference type.

If a manager is viewing form, the 'Employee' variable should show manager's reports and also manager name

If an employee is viewing form and does not have any reports, 'Employee' variable should show the employee name only.

 

How can I achieve this. Currently I'm able to show reports for manager but how can I also include the manager name

TIA

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@si21 

you can use this reference qualifier along with script include

javascript: new EmployeeUtils().getReportsAndManager();

var EmployeeUtils = Class.create();
EmployeeUtils.prototype = {
    initialize: function() {},

    getReportsAndManager: function() {
        var result = [];
        var userID = gs.getUserID();
        // Check if logged in user is manager of someone
        var reportGR = new GlideRecord('sys_user');
        reportGR.addQuery('manager', userID);
        reportGR.query();
        if (reportGR.getRowCount() > 0) {
            while (reportGR.next()) {
                result.push(reportGR.getUniqueValue());
            }
            // push manager or logged in user also
            result.push(userID);
        } else {
            // logged in user has no reportee
            result.push(userID);
        }
        return 'sys_idIN' + result.toString();
    },

    type: 'EmployeeUtils'
};

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

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@si21 

you can use this reference qualifier along with script include

javascript: new EmployeeUtils().getReportsAndManager();

var EmployeeUtils = Class.create();
EmployeeUtils.prototype = {
    initialize: function() {},

    getReportsAndManager: function() {
        var result = [];
        var userID = gs.getUserID();
        // Check if logged in user is manager of someone
        var reportGR = new GlideRecord('sys_user');
        reportGR.addQuery('manager', userID);
        reportGR.query();
        if (reportGR.getRowCount() > 0) {
            while (reportGR.next()) {
                result.push(reportGR.getUniqueValue());
            }
            // push manager or logged in user also
            result.push(userID);
        } else {
            // logged in user has no reportee
            result.push(userID);
        }
        return 'sys_idIN' + result.toString();
    },

    type: 'EmployeeUtils'
};

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