FLow designer Approval

Rajeevreddy
Tera Expert
//we want to send approval to group manager and manager's manager . how to achieve this using flow designer ask for approva;


(function() { var approvers = ''; var grp = new GlideRecord('sys_user_group'); if (grp.get('90dd4dc3db731200fed3b33fdf961917')) { var mgr = grp.getValue('manager'); if (mgr) { approvers = mgr; var usr = new GlideRecord('sys_user'); if (usr.get(mgr)) { var mgr2 = usr.getValue('manager'); if (mgr2) approvers += ',' + mgr2; } } } return 'ApprovesAll[' + approvers + ']RejectsAny[' + approvers + ']'; })();

 

7 REPLIES 7

Itallo Brandão
Tera Guru

Hi @Rajeevreddy ,

 

To help us fix this, could you clarify exactly how it is not working?

  1. Does the Flow execution show an Error state (Red)?

  2. Or does it finish successfully, but the Approvers list is empty?

  3. In the Flow Execution Details, did you check if that specific Group SysID actually exists in the instance you are testing?

Let us know these details so we can provide the correct fix.

Best regards, Brandão.

It is skipping and approvers are empty

Tejas Adhalrao
Tera Guru

Hi @Rajeevreddy ,

 

In Flow Designer, use the Ask for Approval action with Approvers set to Script. Fetch the group manager and the manager’s manager from sys_user_group and sys_user tables, return them as an array, and Flow Designer will handle the approval automatically.

 

Use this script in the Approvers (Script) field:

 

 

(function () {
    var approvers = [];
    var grp = new GlideRecord('sys_user_group');

    // Replace with dynamic group sys_id if possible
    if (grp.get('90dd4dc3db731200fed3b33fdf961917')) {

        // Group Manager
        if (grp.manager) {
            approvers.push(grp.manager.toString());

            // Manager's Manager
            var usr = new GlideRecord('sys_user');
            if (usr.get(grp.manager) && usr.manager) {
                approvers.push(usr.manager.toString());
            }
        }
    }

    return approvers;
})();