cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Workflows: get data from a previous dql task to a new dql or javascript task

JhonU
Guide
Hello everyone, maybe you can guide me. I have a problem. I don't know how I can call the data that two dql code tasks return to me, whether to use it in another dql or javascript task. I've tried using regular expressions, but I can't figure out how to integrate them into code. DQL from a previous task.
For example, the time_validation task returns the hour parameter that I need to use for aggregations in a new task with dql or javascript
JhonU_0-1718796477158.png

 

 

5 REPLIES 5

ChristopherHejl
Inactive

You can access task result data in other tasks using expressions, specifically the result expression https://docs.dynatrace.com/docs/shortlink/automation-workflow-expression-reference#result

In your example, you have a task "time_validation" with a result: records[{hour: 21, even....} .. ]
So in order to access the property hour in the first item of the records list, the expression would be

{{ result("execute_dql_query_1")["records"][0]["hour"] }}

ChristopherHejl_0-1718797890689.png

Given that the DQL query records are always a list, you might want to loop over them and grab the hour, for example

{% for record in result("execute_dql_query_1")["records"] %}
	My Hour : {{ record.hour }}
{% endfor %}

ChristopherHejl_1-1718798008912.png

Those expression can be used in any task input of any action with the exception of custom javascript, as this could lead to unwanted code injection. Therefore there is a javascript native option to access task results described here: https://docs.dynatrace.com/docs/platform-modules/automations/workflows/default-workflow-actions/run-...

Note: in order to access task results, the source task needs to be a predecessor to the task where you reference its result. However it does not have to be the immediate predecessor. Assuming a linear workflow with 5 tasks, task 5 can still access any result from task 1-4.

Thank you for your answer, however it gives me an error when calling the result of the previous task as proof I am calling the total value of the previous task "request_validation" as seen in the image, the error log tells me that the variable does not exist

JhonU_0-1718798875392.png

JhonU_2-1718799251145.png

 

JhonU_1-1718798967848.png

 

the expression looks good. Can you share the exact error message?
Also to make sure the tasks have a dependency with each other, can you share the conditions tab from the time_validation task?

MariettaAlmeida
Organizer

hi there, im facing the same issue when developing a workflow that must send an email when the JVM% threshold is reached. Im using  a DQL query that brings records ( jvm metric from diferent processes) and what we must do is: if the metric of any of those processes is above 80%, send the email alert (on a next step we want to alert also through ansible) so far the the DQL gives me this data: 

MariettaAlmeida_0-1734534250517.png

MariettaAlmeida_1-1734534293068.png

 

but when doing the condition on the next step it fails 

MariettaAlmeida_2-1734534418097.png

 

im using the records variable from the last step that brings the 8 records but on the email step it shows othe info and doesnt work.

thanks in advance 🙂

I may have the same stuborn issue here, did you solve your problem at the end?

I have two tasks  the first task called input which is javascript code which simply returning a JSON  and I can see it in the results showing this results

 

{
"to": "now()",
"from": "now()-7d",
"display_id": "P-250917044"
}

The task after that I use the following DQL:

 

fetch dt.davis.problems, from:now()-7d, to:now()
| filter display_id == "{{ result('input').get('display_id', "undefined") }}"
| filter event.kind == "DAVIS_PROBLEM"
| filter maintenance.is_under_maintenance == false
| filter event.status == "CLOSED" and not dt.davis.is_duplicate == "true"
| fields dt.davis.affected_users_count

 

Whatever I use with all the codes described in the Dynatrace documentation is failing  

so I used this jinja expression but is always returning the default value I put which undefined

 

{{ result('input').get('display_id', "undefined") }}

 

What am I doing wrong? I used many workflows in loops in previous workflows and they all work

but not the input to a DQL from a previous task - something does not make sense?

 

The documentation gives the following but they all do not work when I tried them so I used the .get method

but it can not find my key

 

# result of 'task_1' in the workflow
{{ result('task_1') }}

# result attribute 'foo' of 'task_1'
# the result function allows to only return part of the object
# if the result object does not have an attribute "foo", the function will fail with an "Undefined variables" message
{{ result('task_1.foo') }}

# alternatively, the whole result object can be returned and afterwards access the attributes of the object
# if the result object does not have an attribute "foo", the expression will fail with an "Undefined variables" message
{{ result('task_1').foo }}

# both options can be combined, for example, with a default filter (see filters)
{{ result('task_1').foo | default('foo is not defined') }}`

# however for the following, at least the "foo" attribute needs to exist otherwise the same error will occour
{{ result('task_1').foo.bar | default('foo is not defined') }}`

# the get function can also be used to access object attributes
{{ result('task_1').get('foo', 'foo is not defined') }}

 

 

 

 

 

Your help is much appreciated.

 

Featured Posts