02 Apr 2024 05:52 PM - last edited on 03 Apr 2024 11:00 AM by Michal_Gebacki
Hello, good day, I am starting to work with the workflows, in the example that I am building I make an http request, which results in a JSON file, which is what interests me since it brings all the data I need, my question is how can I get that json and work on it in the next task, I was reviewing the documentation and I see a result function but I can't quite understand how it works, I don't know if anyone has a similar example, thank you very much in advance
Solved! Go to Solution.
02 Apr 2024 10:45 PM
Hola Jorge, let me see if I can help a bit.
You can access the results of the previous steps using the following expressions:
https://docs.dynatrace.com/docs/shortlink/automation-workflow-expression-reference#result
You can use this syntaxis inside the options and parameters of the following steps.
If the returned object has attributes or more properties you can access them as well using something like:
{{ result('task_1').foo }}
Works as well when working with JSON objects. Most of the tasks return a JSON result object.
If you need to work with the previous results inside a Javascript task and code, you can work with something like in this example:
https://docs.dynatrace.com/docs/shortlink/davis-workflow-integration#evaluate
As you can see you can store the resulting object from a previous task, or even create a new array to store the whole results. In that example they use:
const TASK_ID = 'predict_disk_capacity'; //here you put the name of the previous task
const predResult = await exe.result(TASK_ID); //store the whole result in a new variable
const result = predResult['result']; //a new variable to store only the result part
Then you can work with result to traverse it or access any particular value.
Best regards,
Jose David.