Switch
A decision task is similar to case...switch statement in a programming language.
Json
Example
json
{
"name": "switch_task",
"taskReferenceName": "switch_task",
"inputParameters": {
"switchCaseValue": "${workflow.input.service}"
},
"type": "SWITCH",
"evaluatorType": "value-param",
"expression": "switchCaseValue",
"defaultCase": [
{
...
}
],
"decisionCases": {
"case_1": [
{
...
}
],
"case_2": [
{
...
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Definition
Property | Type | Required | Description |
---|---|---|---|
The name (or type) of the task | |||
The unique name of the task in your job. It is used to reference this task in the workflow. | |||
The functional description of this task in your job. | |||
The type of the task. It must be SUB_WORKFLOW . | |||
true : the job continues if there is an error on this task. false : the job fails. | |||
Input parameters of the task. See below |
Inputs
Property | Type | Description |
---|---|---|
evaluatorType | : | Default: javascript - value-param : Use a parameter directly as the value to determine the list of tasks to execute - javascript : Evaluate a javascript expressions and use its result as the value to determine the list of tasks to execute |
expression | If the evaluatorType is value-param , the value of the parameter is used as the value to evaluate. If the evaluatorType is javascript , the value of the parameter is used as the expression to evaluate. | |
decisionCases | Object where the key is a possible value that can result from the expression being evaluated by evaluatorType ant the value associated is a list of tasks to be executed | |
defaultCase | List of tasks | List of tasks to be executed when no matching value is found inside the decisionCases parameter |
Outputs
Property | Description |
---|---|
evaluationResult | Array of String A List of string representing the list of cases that matched. |
Examples
Example using a parameter as the value
In the example below, we use a SWITCH
task to determine which action should follow an file-generation-archive
task:
- If every archive has been generated, we will prompt a success message to the user
- If not, we will prompt an error message
Of course, in a real use case, we would probably want to execute more logic in case of failure.
json
{
"schema": "1.0",
"key": "switch-simple-using-value",
"title": "Simple SWITCH example using a value from a previous task",
"tasks": [{
"name": "file-generation-archive",
"taskReferenceName": "file_generation_archive",
"description": "File generation archive - Will not generate one of the three archives",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/request.xml",
"allowPartial": false
}
}, {
"name": "switch_task",
"taskReferenceName": "switch_task",
"inputParameters": {
"switchCaseValue": "${file_generation_archive.output.allFilesGenerated}"
},
"type": "SWITCH",
"evaluatorType": "value-param",
"expression": "switchCaseValue",
"defaultCase": [{
"name": "notification-display-message",
"taskReferenceName": "notification_display_message_default",
"description": "Notification display message - default case",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/default.html",
"height": 300
}
}
],
"decisionCases": {
"YES": [{
"name": "notification-display-message",
"taskReferenceName": "notification_display_message_yes",
"description": "Notification display message - YES",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/all_files_generated_yes.html",
"height": 300
}
}
],
"NO": [{
"name": "notification-display-message",
"taskReferenceName": "notification_display_message_no",
"description": "Notification display message - NO",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/all_files_generated_no.html",
"height": 300
}
}
]
}
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Example using a JavaScript expression as the value
In the example below, we use a SWITCH
task and a javascript
expression to determine which action should follow an file-generation-archive
task:
- If the number of archives generated is strictly superior to
1
, we will prompt a success message to the user - If not, we will prompt an error message
Another use case may be to determine if any file is generated at all, before trying to send them somewhere (using an FTP task for example)
json
{
"schema": "1.0",
"key": "switch-simple-using-javascript-expression",
"title": "Simple SWITCH example using a javascript expression",
"tasks": [{
"name": "file-generation-archive",
"taskReferenceName": "file_generation_archive",
"description": "File generation archive - Will not generate one of the three archives",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/request.xml",
"allowPartial": false
}
}, {
"name": "switch_task",
"taskReferenceName": "switch_task",
"inputParameters": {
"inputValue": "${file_generation_archive.output.files}"
},
"type": "SWITCH",
"evaluatorType": "javascript",
"expression": "$.inputValue.length > 1 ? 'success' : 'failure'",
"defaultCase": [{
"name": "notification-display-message",
"taskReferenceName": "notification_display_message_default",
"description": "Notification display message - default case",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/default.html",
"height": 300
}
}
],
"decisionCases": {
"success": [{
"name": "notification-display-message",
"taskReferenceName": "notification_display_message_yes",
"description": "Notification display message - YES",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/all_files_generated_yes.html",
"height": 300
}
}
],
"failure": [{
"name": "notification-display-message",
"taskReferenceName": "notification_display_message_no",
"description": "Notification display message - NO",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "file://assets/all_files_generated_no.html",
"height": 300
}
}
]
}
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Limits and additional notes
Details regarding the tasks executed inside the SWITCH
task are not visible in job execution details. We recommend the use of the outputParameters
to display necessary information regarding what happened inside the SWITCH
task (files generated, errors, etc.)