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

**URL:** <https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209>\
**Category:** Automations\
**Tags:** workflows\
**Created:** [June 19, 2024, 11:32am UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209 "2024-06-19T11:32:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JhonU](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JhonU](https://community.dynatrace.com/u/JhonU)\
**Post date:** [June 19, 2024, 11:32am UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/1 "2024-06-19T11:32:21Z")

</div>

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](https://global.discourse-cdn.com/dynatrace/original/3X/8/a/8a4f96104c0706ea2c4c4f73b0b308e4d4af6fdb.png)

---

<div class="post-metadata">

**Author:** ![ChristopherHejl](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christopherhejl/32/20735_2.png) [@ChristopherHejl](https://community.dynatrace.com/u/ChristopherHejl)\
**Post date:** [June 19, 2024, 11:55am UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/2 "2024-06-19T11:55:35Z")

</div>

You can access task result data in other tasks using expressions, specifically the **result** expression [Jinja expressions for Workflows — Dynatrace Docs](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

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

```

 ![ChristopherHejl_0-1718797890689.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/141741225ead62633cd28231fc8abadcc7239ff4.png)

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

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

```

 ![ChristopherHejl_1-1718798008912.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/a/5a8fc927dc2239932cff669f70671648911f7bd2.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: [Run JavaScript action for Workflows — Dynatrace Docs](https://docs.dynatrace.com/docs/platform-modules/automations/workflows/default-workflow-actions/run-javascript-workflow-action)

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.

---

<div class="post-metadata">

**Author:** ![JhonU](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JhonU](https://community.dynatrace.com/u/JhonU)\
**Post date:** [June 19, 2024, 12:12pm UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/3 "2024-06-19T12:12:03Z")

</div>

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](https://global.discourse-cdn.com/dynatrace/original/3X/6/f/6fadc6a1ac93847a5516e73aa672a6370416b7bc.png)

 ![JhonU_2-1718799251145.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/fa2be1f6852694ddd5bc7f35ec43f1c4e5c1b815.png)

 ![JhonU_1-1718798967848.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/5/755983894d303a9615f2632219168226d8c630a4.png)

---

<div class="post-metadata">

**Author:** ![ChristopherHejl](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christopherhejl/32/20735_2.png) [@ChristopherHejl](https://community.dynatrace.com/u/ChristopherHejl)\
**Post date:** [June 19, 2024, 12:21pm UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/4 "2024-06-19T12:21:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MariettaAlmeida](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@MariettaAlmeida](https://community.dynatrace.com/u/MariettaAlmeida)\
**Post date:** [December 18, 2024, 3:07pm UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/5 "2024-12-18T15:07:50Z")

</div>

hi there, im facing the same issue when developing a workflow that must send an email when the JVM% threshold is reached. Im using&nbsp; 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](https://global.discourse-cdn.com/dynatrace/original/3X/0/a/0a4d1585388653d50f8d1f19f2839055cdbc1144.png)

 ![MariettaAlmeida_1-1734534293068.png](https://global.discourse-cdn.com/dynatrace/original/2X/8/8858506087751df51a1fbfeab2238aa332158ae1.png)

but when doing the condition on the next step it fails

 ![MariettaAlmeida_2-1734534418097.png](https://global.discourse-cdn.com/dynatrace/original/3X/a/6/a6bd5dc6f2e633468d950b00b940292e878b5259.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 🙂

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [October 3, 2025, 10:06pm UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/6 "2025-10-03T22:06:14Z")

</div>

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

I have two tasks&nbsp; the first task called input which is javascript code which simply returning a JSON&nbsp; 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.

---

<div class="post-metadata">

**Author:** ![zaid-bashir](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/zaid-bashir/32/22651_2.png) [@zaid-bashir](https://community.dynatrace.com/u/zaid-bashir)\
**Post date:** [November 15, 2025, 6:52pm UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/7 "2025-11-15T18:52:31Z")

</div>

Hello&nbsp;[@JhonU](https://community.dynatrace.com/user/75688)&nbsp;[@MarwanC](https://community.dynatrace.com/user/64346)&nbsp;[@MariettaAlmeida](https://community.dynatrace.com/user/59040)&nbsp;[@ChristopherHejl](https://community.dynatrace.com/user/44096)&nbsp;  
I have seen that the solution to get data from previous task in the next task (execute DQL Query) is given by various guys below. But to get that data in Javascript is a bit missing here. I am giving you below the instructions to get data in javascript task as well.

Lets Consider the Scenerio as shown below.

**On Demand Trigger** ==\> **Execute DQL Task(dql\_query\_1)**&nbsp; ==\> **Javascript Task (run\_javascript-task\_1)**

Now You want to get the data or do furthur processing from&nbsp; **dql\_query\_1** to **run\_javascript\_task\_1.** In the Javascript task code, paste the below snippet and replace your DQL task name with yours and execute the workflow and check the results tab of Javascript task.

**Note**  **:** By Default, the **result** function is not imported in javascript task, only **execution** function is imported. So you must import result function and then use as shown below in code.

```javascript
import { execution,result } from '@dynatrace-sdk/automation-utils';

export default async function ({ executionId, actionExecutionId }) {
  var myResult = await result('dql_query_1');
  var finalData = myResult["records"]
  var prcTech = [];
  for (let pointer = 0; pointer < finalData.length; pointer++){
    prcTech[pointer] = finalData[pointer]["status"]
  } 

  return {"prcTech" : prcTech}
  // console.log('Workflow execution id: ', executionId);
  // console.log('Action execution id: ', actionExecutionId)
}

```

In the above example, I am fetching only the status of Logs and Put Them In Dedicated List.  
[  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”,  
“INFO”  
]

I hope you got the idea, Thanks

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [November 28, 2025, 9:20am UTC](https://community.dynatrace.com/t/workflows-get-data-from-a-previous-dql-task-to-a-new-dql-or-javascript-task/46209/8 "2025-11-28T09:20:09Z")

</div>

I fixed indeed in that way, thank you. However, I found a defect in the workflow that if you add documentation at the top of the DQL like a comment or something this functionality brakes and hence that this did not work before, I think this defect needs to be reported to Dynatrace.
