15 May 2025
12:45 AM
- last edited on
15 May 2025
08:00 AM
by
MaciejNeumann
Is it possible to create a workflow where the result of a DQL query is passed to a Javascript action, and that action writes the result to a file somewhere (assume this is SaaS), and then a Notebook displays the data from that file via a javascript action? The usecase is to have the workflow query a lot of data at night, write it to a file, and then have it available for viewing in a Notebook. I'd like to see sample code if this is possible.
Solved! Go to Solution.
16 May 2025 11:29 PM - edited 16 May 2025 11:30 PM
When a DQL query is executed as part of a workflow, the results are already stored as part of the workflow execution. You can just use the existing 'executionsClient' module from the automation-client SDK within a 'Code' tile to do the following:
1. Get the execution ID from the most recent execution of your workflow
2. Use the execution ID from step 1 above to then retrieve the results from the specific workflow step within that particular execution.
The resulting code looks like this:
import { executionsClient } from "@dynatrace-sdk/client-automation";
export default async function () {
// Get the last successful execution of the workflow
const workflow_executions = await executionsClient.getExecutions({
workflow: "<workflow_id_here>",
ordering: "-endedAt",
state: "SUCCESS"
});
const last_execution = workflow_executions.results[0].id;
// fetch the result(s) from the workflow task
const myData = await executionsClient.getTaskExecutionResult({
executionId: last_execution,
id: "<step_name_here>"
});
return myData;
}
19 May 2025 03:19 PM
Thank you Marco. How do you export the result into a file (assuming this is SaaS) with data spanning the last 3 months, and then have a notebook or dashboard load those results from the file into tables and charts at a later time? For example, the workflow would kick off at 12 AM and write the results to a file. Then, users can later view the results in a dashboard or notebook.
19 May 2025 08:15 PM
Dynatrace SaaS doesn't currently provide any built-in storage of 'files' in the traditional sense. It sounds as though you are looking to visualize workflow output across several months, so perhaps your workflow could use the 'S3: Put Object' action to store the data in an S3 bucket, and then you can retrieve the data at a later date via another workflow or via a code tile within your notebook/dashboard.