02 Jul 2024 01:07 PM - edited 02 Jul 2024 01:08 PM
Hello workflow fans! 😀
I have a task that can be triggered by two predecessors.
I want to use there result in this task. Is there a decent way to do this?
Or do I need to a "if empty then the other on"?
KR Henk
Solved! Go to Solution.
02 Jul 2024 01:18 PM
Hi Henk,
a more detailed example would help to better answer the question, I'll try my best with some assumptions:
A task can have multiple predecessors. In order to add dependencies (the lines in the graph) you can click and hold the (+) icon and drag it onto the task you want to draw the line:
In this case, task_3 only runs once both task_1 and task_2 are finished.
Task_3 then has access to both of their results as normal:
If however task_1 and/or task_2 might fail, and you still want to run task_3, then you have to adapt the conditions of task_3 accordingly (eg to any state, the color of the lines will change between red, green and black to indicate the dependency):
In this case, task_3 might run even though task_2 or task_1 or both failed and don't provide a result. You can use tools like if (https://docs.dynatrace.com/docs/platform-modules/automations/workflows/reference#if-statement) or default filter (https://docs.dynatrace.com/docs/platform-modules/automations/workflows/reference#filters)
02 Jul 2024 01:36 PM
Hi Christopher,
You are doing an excellent job! Sorry my question are sometime a little vague. Above already helps a lot, thanks!
To make above complete, suppose you have control over 1 and 2, so only one gets run and the other is skipped.
II suppose in step 3 you have to "try" to retrieve the return of 1 and 2?
Or am I trying something stupid?
Use case: you have green and a blauw events. You send green to 1 and blauw to 2. Then 3 will finish. 3 needs the result of 1 or 2 to proceed.
KR Henk
02 Jul 2024 02:05 PM
Correct, then you can check which one was successful. For this, you can use the task expression to get metadata on a task (Expression reference - Dynatrace Docs).
Example:
{% if task("task_1").state == "SUCCESS" %}
Task 1 did run, result: {{ result("task_1") }}
{% else %}
Task 2, result: {{ result("task_2") }}
{% endif %}
02 Jul 2024 02:17 PM
Again, perfect!