Filtro

larissaribe
Tera Contributor

I need to create a filter that takes the logged-in user in the variable set (it will always be a manager) and only displays users who have the logged-in user as their manager in the employee name field. The employee name field is a reference type for the sys_user table.

2 ACCEPTED SOLUTIONS

SP22
Giga Sage
Giga Sage

Hello @larissaribe,

Option 1: 
If this variable is reused across many items, move the logic into a Script Include so you can maintain it in one place.

Script Include (server‑side, not client‑callable):

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

    getDirectReportsQuery: function () {
        // Add any additional constraints here
        return 'manager=' + gs.getUserID() + '^active=true';
    },

    type: 'DirectReportsUtil'
};

 

On the variable, set Reference qualifier to Advanced and use:

// Use a JavaScript expression to invoke the Script Include
answer = new DirectReportsUtil().getDirectReportsQuery();

 

Option 2: 

Use this when the variable is a reference to sys_user.

  1. Open your variable (inside the variable set).
  2. Set:
    • Type: Reference
    • Reference: sys_user
    • Reference qualifier: Advanced
  3. In Advanced reference qualifier (script) paste:
    // Returns only the direct reports of the logged-in user
    // (OPTIONAL) appends active=true to avoid inactive users in the list
    answer = 'manager=' + gs.getUserID() + '^active=true';​

    That’s it. The reference field will now only display users whose manager equals the current (logged‑in) user.

If this helped to answer your query, please mark it helpful & accept the solution.

Thanks
Santosh.p

 

 

View solution in original post

RaghavSh
Kilo Patron

I believe you have already achieved the loggedin user part so for employee part add the below reference qualifier advanced condition of employee.

 

javascript:”manager=“+current.variables.requested_for; 

// replace &colon with “:” and check the variable name having manager and replace it for requested_for


Please mark the answer correct/helpful accordingly.

 


Raghav
MVP 2023
LinkedIn

View solution in original post

2 REPLIES 2

SP22
Giga Sage
Giga Sage

Hello @larissaribe,

Option 1: 
If this variable is reused across many items, move the logic into a Script Include so you can maintain it in one place.

Script Include (server‑side, not client‑callable):

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

    getDirectReportsQuery: function () {
        // Add any additional constraints here
        return 'manager=' + gs.getUserID() + '^active=true';
    },

    type: 'DirectReportsUtil'
};

 

On the variable, set Reference qualifier to Advanced and use:

// Use a JavaScript expression to invoke the Script Include
answer = new DirectReportsUtil().getDirectReportsQuery();

 

Option 2: 

Use this when the variable is a reference to sys_user.

  1. Open your variable (inside the variable set).
  2. Set:
    • Type: Reference
    • Reference: sys_user
    • Reference qualifier: Advanced
  3. In Advanced reference qualifier (script) paste:
    // Returns only the direct reports of the logged-in user
    // (OPTIONAL) appends active=true to avoid inactive users in the list
    answer = 'manager=' + gs.getUserID() + '^active=true';​

    That’s it. The reference field will now only display users whose manager equals the current (logged‑in) user.

If this helped to answer your query, please mark it helpful & accept the solution.

Thanks
Santosh.p

 

 

RaghavSh
Kilo Patron

I believe you have already achieved the loggedin user part so for employee part add the below reference qualifier advanced condition of employee.

 

javascript:”manager=“+current.variables.requested_for; 

// replace &colon with “:” and check the variable name having manager and replace it for requested_for


Please mark the answer correct/helpful accordingly.

 


Raghav
MVP 2023
LinkedIn