Rules for automation: example 8
Assigning the task to the correct team via an if-then-else operator
Let's assume we have a request "Move desktop PC to a new location". This request is assigned to the team “End user support, Samara”. The coordinator of this team needs to reassign the request to the team “End user support, Moscow”, if the initiator belongs to “Manufacturing organization”, or to the team “End user support, Voronezh”, if the initiator belongs to “Research and Development Center”. To reassign tasks, you can use an automation rule.
Below are the main elements of such an automation rule.
Trigger
The rule should run when a workflow and tasks are created. Therefore, in the "Trigger" field, select ‘On creation’.
Expressions
The following expressions are defined for the rule. They will be used later to define the condition and actions of the rule:
1. request
The expression request is used to find the first request related to the workflow to which the task belongs. You can get information about the organization initiating the request from this request. In general, you can use one expression for this, but using three expressions provides more advantages: all three expressions will be logged during rule execution, which better reflects its purpose. The expression is defined as follows:
workflow.requests[first]
2. requester
The expression requester is used to get information about the user indicated in the “Requested for” field. This expression is defined as follows:
request.requested_for
3. organization
The expression organization is used to get information about the organization that the user indicated in the “Requested for” field. This expression is defined as follows:
requester.organization
4. old_team_name
The expression old_team_name is used to get information about which team the task was initially assigned to. This expression is defined as follows:
team.name
5. is_from_manuf
The expression is_from_manuf is used to check if the initiator belongs to “Manufacturing organization”. This expression is defined as follows:
organization contains 'Manufacturing organization'
6. new_team_name
The expression new_team_name is used to reassign the task to a new team if the initiator belongs to “Research and Development Center”. A ternary (conditional) operator if then else is used, which takes three arguments: A – the comparison argument, B – the result if the comparison is true, and C – the result if the comparison is false. The first argument A – is the comparison argument, the second argument B - is the result if the comparison is true, and the third argument C – is the result if the comparison is false. This expression is defined as follows:
is_from_manuf then 'End user support, Moscow' else old_team_name
7. is_from_rd_center
The expression is_from_rd_center is used to check if the initiator belongs to “Research and Development Center”. This expression is defined as follows:
organization contains 'Research and Development Center'
8. new_team_name
The expression new_team_name is used to reassign the task to a new team if the initiator belongs to “Research and Development Center”. This expression is defined as follows:
is_from_rd_center then 'End user support, Voronezh' else new_team_name
9. move_task
The expression move_task is used to identify the task of moving a desktop PC. Since the topic of this task is ‘Move desktop PC to a new location’, this expression is defined as follows:
workflow.tasks['Move desktop PC to a new location']
9. update_cmdb
The expression update_cmdb is used to identify the task of changing the location of a desktop PC in the CMDB record. Since the topic of this task is ‘Specify new location in CMDB record for PC’, this expression is defined as follows:
workflow.tasks['Specify new location in CMDB record for PC']
Condition
After defining the expressions, you need to set a condition under which the automation rule is executed. In this example, the rule runs if the initiator belongs to “Manufacturing organization” or “Research and Development Center”. The condition is defined as follows:
is_from_manuf or is_from_rd_center
Update 1: Selecting the team for assigning task ‘Confirm network connection availability’.
The rule updates the task ‘Confirm network connection availability’. Since this is a task for which an automation rule has been defined, you do not need to fill the “Update” field. In this case, the default value is assigned to the current record.
Set
The goal of the rule is to select a new team for assigning the current task, so the “Set” field is specified as follows:
team = new_team_name
Update 2: Selecting the team for assigning task ‘Move desktop PC to a new location’.
The previously defined expression move_task identifies this task, so it is selected in the “Update” field.
Set
The goal of the rule is to select a new team for assigning the current task, so the “Set” field is specified as follows:
team = new_team_name
Update 3: Selecting the team for assigning task ‘Specify new location in CMDB record for PC’.
The previously defined expression move_task identifies this task, so it is selected in the “Update” field.
Update 4: No assigned participant in task ‘Confirm network connection availability’.
The rule updates the task ‘Confirm network connection availability’. Since this is a task for which an automation rule has been defined, you do not need to fill the “Update” field. In this case, the default value is assigned to the current record.
Set
The automation rule will not be executed if a specialist from the new team is not specified in the task’s “Participant” field. Therefore, the “Set” field is specified as follows:
member = empty
Update 5: No assigned participant in task ‘Move desktop PC to a new location’.
The previously defined expression move_task identifies this task, so it is selected in the “Update” field.
Set
The automation rule will not be executed if a specialist from the new team is not specified in the task’s “Participant” field. Therefore, the “Set” field is specified as follows:
member = empty
Update 6: No assigned participant in task ‘Specify new location in CMDB record for PC’.
The previously defined expression update_cmdb identifies this task, so it is selected in the “Update” field.
Set
The automation rule will not be executed if a specialist from the new team is not specified in the task’s “Participant” field. Therefore, the “Set” field is specified as follows:
member = empty