Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Group Approval - Based on members employment type

RitikH
Tera Contributor

Hi All, 

 

We have a requirement that there should be a group approval triggered to the CI Business Service group's only permanent employee. Like the if the group has 5 members and 3 out of them are contractors it should be any one approve for the rest two permanent employee.

 

Thanks

Ritik

3 REPLIES 3

Naveen20
ServiceNow Employee

Try this

Flow Designer Approach

Instead of a group approval activity, use a Script Step to create filtered approvals, then an Wait for Condition or Approval activity:

// Script Step: Create approvals for permanent employees only
(function execute(inputs, outputs) {
    var members = new GlideRecord('sys_user_grmember');
    members.addQuery('group', inputs.group_sys_id);
    members.query();

    while (members.next()) {
        var user = members.user.getRefRecord();
        if (user.getValue('employee_type') != 'contractor') {
            var appr = new GlideRecord('sysapproval_approver');
            appr.initialize();
            appr.setValue('sysapproval', inputs.record_sys_id);
            appr.setValue('approver', user.getUniqueValue());
            appr.setValue('state', 'requested');
            appr.setValue('source_table', inputs.table_name);
            appr.insert();
        }
    }
})(inputs, outputs);

Then add a Wait for Condition step:

Table: sysapproval_approver → where sysapproval = record_sys_id AND state = approved → exists

Once any one approves, the flow continues and you run a second script step to set remaining approvals to not_required.

Adjust employee_type != 'contractor' to match whatever field your instance uses to flag contractors (could be a custom field like u_is_contractor or an HR profile attribute).

Ankur Bawiskar
Tera Patron

@RitikH 

you can use scripted approval in flow and grab only those 3 members i.e. permanent

Scripted Approvals in Flow Designer with Flow Variables 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@RitikH 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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