Approval - Group workflow activity

The Approval - Group activity creates approval records for each member of a specified group.

The group approval is approved or rejected based on the user approvals, according to the logic specified in the Wait For field.

Results

The workflow designer can assign a result value using activity.result from within a script field of the activity. By default, the result value is the final approval disposition. This disposition depends on the approval actions take by the approvers and the approval conditions specified in the Wait for or When Anyone Rejects fields. Possible result values are:
  • Approved
  • Rejected
  • Deleted
  • Cancelled

Input variables

Input variables determine the initial behavior of the activity.

Table 1. Approval - Group activity input variables
Field Description
Condition Conditions which, if met, cause the group approval to be generated. If the conditions are not met, the approval is skipped.
Wait for
A choice between different approval logics to determine which individual approvals or rejections result in approval or rejection of the activity's approval. Options are:
  • An approval from each group: Any user from each group can approve and the first approval from each group causes the activity to complete with a result of approved (see below for how a rejection is handled).
  • An approval from any group: Any user from any group can approve and the first approval from any group causes the activity to complete with a result of approved.
  • An approval from everyone from all groups: All users from all groups must approve to cause the activity to complete with a result of approved (see below for how a rejection is handled).
  • First response from each group: The first approval or rejection from any user in each group is used to indicate the state of the group approval (see below for how a rejection is handled).

    Indicate what happens when any user rejects their approval request. Options are:

  • Reject the approval: Immediately complete the activity with a result of rejected.
  • First response from any group: The first approval or rejection from any user in any group causes the activity to complete with a result of approved or rejected.
  • Condition based on script: Each time a user approves or rejects, the Approval script is called to determine if the activity should complete.
When anyone rejects
A choice between different approval logics to determine which individual rejections result in rejection of the activity's approval. Options are:
  • Reject the approval: Immediately complete the activity with a result of rejected.
  • Wait for other responses before deciding: Wait until we get other responses before making an approval or rejection decision. This allows users to change their mind until a decision is made.
Note: If Wait for is set to Anyone to approve, then a single approval causes the activity to complete with a result of approved, even if one or more users reject.
Groups The groups whose approval will be requested. A particular group can be selected, or the tree icon can be used to select a group field from the current record. A user approval for each member of the group is automatically created when a Group approval record is created. If no group is selected, the activity automatically sets the approval to Approved.
Advanced Select this check box to write a script for determining additional users to request approvals from. Use the Additional groups script to customize group approvals.
Due date based on The due date fields are used to determine the values to use for setting Expected Start Time and Due Date for the task. The type determines how the due date is computed:
  • A user specified duration: The duration is based on a user specified value.
  • A relative duration: The duration is calculated from a relative duration (such as End of Next Business Day).
  • A date/time or duration field: The duration is based on the value of a field on the current record.
  • Script: The duration is returned by a script.
Duration The specific number of days and hours. This field is available only when Due date based on is A user specified duration.
Relative duration The general number and length of business days. This field is available only when Due date based on is A relative duration.
Due date field The date/time or duration field. This field appears when the Due date based on is A date/time or duration field.
Due date script The script that sets 'answer' to the number of seconds for the duration. This field is available only when Due date based on is Script.
Schedule based on The basic schedule the timer uses to count working hours. If a schedule is specified, the duration will only be considered for times that are specified on the schedule. For example, if the duration is 2 hours and the workflow begins at 4:00pm on a schedule that is 8am - 5pm, then it ends at 9:00am the next day. The options are:
  • This workflow's schedule: The schedule uses workflow context date, time, and an optional Time zone based on value.
  • A specific schedule: The schedule uses a pre-defined Schedule and an optional Time zone based on value.
  • A schedule field: The schedule uses a value from a table and an optional Time zone based on value.
Schedule The predefined Schedule from a list. This field available only when Schedule based on is A specific schedule.
Schedule field A date and time or duration field for the schedule, that is associated with the table. Valid fields appear in blue on the Select the element from a tree dialog. This field is available only when Schedule based on is A schedule field.
Time zone based on The time zone for calculating the duration. The time zone may be based on:
  • No time zone: Default. Workflow uses the GMT time zone.
  • A specific time zone: A predefined Time zone.
  • A time zone field: A Time zone field to track time duration from a field on the form.
Time zone The predefined time zone. This field is available only when Time zone based on is A specific time zone.
Time zone field A date and time or duration field for the schedule, that is associated with the table. Valid fields appear in blue on the Select the element from a tree dialog. This field is available only when Time zone based on is A time zone field.
Additional groups script
If the Advanced check box is selected, this script is called to determine any additional group approvals to be created. The script needs to set the variable answer to a comma-separated list of group ids or an array of group ids to add as approver groups. For example:
answer = [];
       answer.push('id1');
       answer.push('id2');
Approval script

If the Wait for variable is set to Condition based on script this script is called to determine how to handle an approval or rejection. The script needs to set the variable answer to approved or rejected to indicate the overall approval status for this approval.

This script is responsible for setting the approval state for each group that is part of this approval activity before returning the overall approval state for all of the groups.

When called, the following variables are available to the script for all the groups that are part of this approval activity:

counts.total = total number of groups that are part of this approval
          counts.approved = # of groups that approved so far
          counts.rejected = # of groups that rejected so far
          counts.requested = # of groups that are pending approval
          counts.not_requested = # of groups that are not pending approval
          counts.not_required = # of groups that approval is not required
And for each group:
groups[group_id].total = total number of users that are part of this group's approval
           groups[group_id].approved = # of users that approved so far
           groups[group_id].rejected = # of users that rejected so far
           groups[group_id].requested = # of users that are pending approval
           groups[group_id].not_requested = # of users that are not pending approval
           groups[group_id].not_required = # of users that approval is not required
           groups[group_id].approvalIDs[state] = array of user ids that are at the specified approval state
Note: Iterate the groups using:
for (var id in groups) {
          var group = groups[id];
          ... group.total ...
       }
Note: Get group object using the following code (to get things like the group name being iterated on):
var objGroup = fncGetGroupObj(id);
var strGroupName = objGroup.name;
 
function fncGetGroupObj(sidGroupApproval)
{
	var objGroupApproval = new GlideRecord('sysapproval_group');
	objGroupApproval.get(sidGroupApproval);
 
	var objGroup = new GlideRecord('sys_user_group');
	objGroup.get(objGroupApproval.assignment_group.sys_id);
 
	return objGroup;
}
Approval scripts also allow computations. For example, if only half of the approvals are required:
if (counts.approved/counts.total > .49) {
answer = 'approved';
}
else if (counts.rejected/counts.total > .50) {
answer = 'rejected';
}

Conditions

The following conditions determine which transition runs after this activity.
Table 2. Approval - Group activity conditions
Condition Description
Approved The users from the groups have approved the request based on the Wait for rules.
Rejected The users from the groups have rejected the request based on the Wait for rules.
Error The event or condition that generates an error.
Skipped The event or condition that allows a skipped approval.

States

The activity state tells the workflow engine what to do with the activity.
Table 3. Approval - Group activity states
State Description
Executing The workflow engine starts the execute function of the activity.
Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.
Finished The activity finished running. See the result value for the outcome of the activity.
Cancelled This activity, or the workflow that contains this activity, was canceled.
Error A JavaScript error occurred. Review the logs for error details.