To achieve this in ServiceNow Flow Designer, you can use a combination of the Flow Designer actions, decision tables, and custom script actions to route the approval to a specific member of the assignment group when a task is closed. Here's a step-by-step approach to implement this:
-
Create/Modify the Flow:
- Ensure your flow is set to trigger when a record is created on the
sn_hamp_asset_rma_line table.
- Add actions to create a task on the
sn_hamp_asset_rma_task table.
-
Add Condition to Check Task State:
- Use a "Wait for Condition" action to wait until the task state changes to "Closed".
-
Determine Assignment Group:
- Use a "Script Action" to determine the
assignment_group of the closed task and identify the group.
-
Route Approval to Specific Member:
- Use a decision table to route the approval request to a specific group member based on the assignment group.
Here's a detailed outline of each step:
1. Create/Modify the Flow
Ensure your Flow Designer configuration has steps to create the task and set the necessary fields:
- Trigger: Record created on
sn_hamp_asset_rma_line.
- Action: Create record on
sn_hamp_asset_rma_task.
2. Wait for Task to Be Closed
- Drag and Drop a "Wait for Condition" action:
- Table:
sn_hamp_asset_rma_task
- Conditions:
State is Closed.
3. Identify Assignment Group using Script Action
- Add a "Script Action" after the "Wait for Condition":
- Input Variables:
sys_id of the closed task.
- Use the Script Action to identify the assignment group and the specific member for approval:
(function execute(inputs, outputs) {
var taskSysId = inputs.task_sys_id;
var taskRecord = new GlideRecord('sn_hamp_asset_rma_task');
if (taskRecord.get(taskSysId)) {
var assignmentGroup = taskRecord.assignment_group;
var userId = ''; // find specific member logic goes here
// Add your logic to get a specific user from the group
// For instance, you can set a predefined user attribute or any business rule
// Example: Get first active user from the group
var groupMembers = new GlideRecord('sys_user_grmember');
groupMembers.addQuery('group', assignmentGroup);
groupMembers.addQuery('user.active', true);
groupMembers.query();
if (groupMembers.next()) {
userId = groupMembers.user.sys_id; // the specific user to whom you want to assign the approval
}
// Output the user ID
outputs.user_id = userId;
}
})(inputs, outputs);
Ensure you define the output variable user_id in the Script Action.
4. Send Approval Based on Assignment Group
- Add an "Ask for Approval" action after the Script Action:
- Approval for: Task (or suitable record on the same table you need approval for)
- Approval Group:
sys_user_grmember table user sys_id fetched from the Script Action.
Handling Multiple Groups
Repeat this logic for all groups by creating more complex conditions within the script or by creating multiple branches in your Flow Designer with decision tasks.
Final Outline
- Trigger: Record created on
sn_hamp_asset_rma_line.
- Action: Create
sn_hamp_asset_rma_task with necessary data.
- Action: Wait for Condition – state is closed.
- Script Action: Determine specific user for approval from the assignment group.
- Action: Ask for approval from the specific user.
With this setup, the approval process is dynamically routed to the specific members of the 15 groups depending on the assignment group of the closed task.