granular delegation

muktha1
Tera Guru

Hi friends,

 

In granular delegation, supposing I need to build a delegate user criteria which should satisfy the two below given conditions for HR tasks
Delegator's manager = Delegate's manager
Delegator's Org level=Delegate's Org level (Org level is a field in user table)
In using the advanced script I want to know what user_id refers to ? If it refers to only the delegate sys id, then is there a way we bring in the sysid of the user who has to delegate within the user criteria script for comparing?

Thanks



1 REPLY 1

sanjaygupta
Tera Guru

In a user criteria advanced script, user_id is the user the criteria is being evaluated for. In the Delegate User Criteria, that means each person being checked as a possible delegate. Community examples use user_id in GlideRecord queries on sys_user in the same way, for example to find people reporting to that user.

I did not find documentation of a variable that passes the delegator into the script. A community thread on this exact feature shows current.delegate failing with a null error, so current is not available in this script. Delegator and delegate criteria are also set up separately, on the Delegator User Criteria and Delegate User Criteria tabs of the delegation rule, so each script sees only the user it is evaluating.

The usual workaround is gs.getUserID(), which returns the logged-in user. When an employee delegates from the My Delegates widget, that is normally the delegator. If a delegate admin assigns delegates on someone’s behalf, gs.getUserID() would be the admin, so the comparison would use the wrong user. Confirm this against how your delegations are created.

To build and test it:

  • Go to All > Granular Delegation > Delegation Rules and open your HR task rule.
  • Open the Delegate User Criteria tab and create a user criteria with an advanced script.
  • Add a script along these lines, replacing the Org level field name with the real column on your user table:
 
javascript
answer = false;
var delegator = new GlideRecord('sys_user');
var delegate = new GlideRecord('sys_user');
if (delegator.get(gs.getUserID()) && delegate.get(user_id)) {
    answer = !!delegator.getValue('manager') &&
        delegator.getValue('manager') == delegate.getValue('manager') &&
        delegator.getValue('u_org_level') == delegate.getValue('u_org_level');
}
  • Test as a delegator from the My Delegates widget, and check that a delegate with a different manager or org level is not offered.
  • Check the candidate list as an admin too, to see whether it behaves differently.

Granular delegation does not change a delegate’s access. The delegate still needs the necessary roles to open the records, so check that your delegates have them. This script is a starting point and has not been run against your instance. Build it in a sub-production instance and move it with an update set.

Sources: