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

Workflows access data from another workflow step

vitz
Newcomer

Hi folks,

I need help in writing some JS code for a workflow.

In a previous step i have a HTTP API request the pulls data and returns the payload in JSON. the step name is "sn_step1"

 

{
    "result": [
      {
        "state": "test_state_1",
        "number": "1234567",
        "end_date": "2025-02-28 09:12:19",
        "start_date": "2025-02-27 09:30:15",
        "short_description": "Test 1"
      },
      {
        "state": "test_state_2",
        "number": "1234567",
        "end_date": "2025-02-28 09:12:19",
        "start_date": "2025-02-27 09:30:15",
        "short_description": "Test 2"
      }
   
    ]
  }
 
I need to use number, start_date, end_date values in variables in a downstream step.
 
 Sample code

// import of sdk modules
import { execution } from '@dynatrace-sdk/automation-utils';

export default async function ({ execution_id }) {
const exe = await execution(execution_id);
const checkResult = await exe.result('sn_step1');


const Scope = data[0].json.scope;
return Scope;

console.log(Scope);

 

im just trying to log the output in this step to see if i can pull in the json output from previous step

2 REPLIES 2

ChristopherHejl
Dynatrace Advisor
Dynatrace Advisor

Almost there. You now have the result data in "checkResult". Here is my example code based on your data. I've also attached the whole example workflow which you can upload in the workflows app (upload button next to create workflow,  just upload the json file in the zip):

import { execution } from '@dynatrace-sdk/automation-utils';

export default async function ({ executionId }) {

  const exe = await execution(executionId);
  const checkResult = await exe.result('sn_step1');

  console.log("This is the full result object")
  console.log(checkResult)
  console.log("===============================")
  
  const firstItem = checkResult[0]

  console.log("This is the first item of the list")
  console.log(firstItem)
  console.log("===============================")


  console.log("This is the number of the first item of the list")
  console.log(firstItem.number)
  console.log("===============================")

}

ChristopherHejl_0-1741880818898.png

 



Thanks this is what I was looking for

Featured Posts