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

Javascript action to write result of DQL query to file in a workflow, and then load that data in a Notebook via Javascript action?

Fred_M_Shimaya
Participant

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.

3 REPLIES 3

marco_irmer
Champion

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;

}

 

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.

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.

Featured Posts