23 May 2023 10:27 AM - edited 20 Jul 2023 12:47 PM
How do I access event data or results from a previous workflow step?
Solved! Go to Solution.
23 May 2023 10:39 AM
Data can be accessed from any previous task in a workflow, and it doesn’t have to be its immediate predecessor.
All workflow task results are automatically available without any additional configuration. Access to data is given via the jinja2 expression, the same system and syntax that you might know from solutions like Red Hat Ansible.
Ad-hoc scripts (JavaScript action) has jinja2 expression disabled to mitigate the risk of possible code injections. For these, we provide access to the data via JavaScript SDKs.
13 Feb 2025 06:54 AM - edited 16 Feb 2025 11:28 PM
For anyone else looking for a code snippet, give a trigger + HTTP task called `get_foo`, you can retrieve the results of `get_foo` in a subsequent task like this:
import { execution } from '@dynatrace-sdk/automation-utils';
import { logsClient } from "@dynatrace-sdk/client-classic-environment-v2";
export default async function ({ executionId }) {
const ex = await execution(executionId);
console.log('Automated script execution on behalf of', ex.trigger);
const result = await ex.result('get_foo');
// Endpoint returns a JSON response
// Get JSON
const result_json = result['json'];
// Get the `Answer` field from returned JSON
const json_answer = result['json']['Answer'];
console.log(json_answer);
// Send a log line back into Dynatrace
// Retrieve with DQL
// fetch logs | filter contains(content, "644des93")
logsClient.storeLog({"type": "text/plain; charset=utf-8", "body": "Some log content: a user ID: 644des93"});
return { triggeredBy: ex.trigger };
}