Automations
All questions related to Workflow Automation, AutomationEngine, and EdgeConnect, as well as integrations with various tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I use the result from a previous JavaScript task into a new JavaScript task?

badgerfifteen
Organizer

I have a previous JavaScript task named get_monitoring_config which returns a JSON. However, it is returning as 'undefined' in the console so I can't use it. 

Here is a better snippet of my code:

// optional import of sdk modules
import { execution, result } from '@dynatrace-sdk/automation-utils';
import { extensions_2_0Client } from "@dynatrace-sdk/client-classic-environment-v2";

 
export default async function (executionId, actionExecutionId) {

const exe = await execution();
const TASK_ID = 'get_monitoring_config'; 
const predResult = await exe.result(TASK_ID); 
const result = predResult['result']; 
console.log(result);

 

1 REPLY 1

sujit_k_singh
Champion

Hi @badgerfifteen 

I think there are two issues in your code.

1. Function signature

Your snippet has:

export default async function (executionId, actionExecutionId) {.....

Dynatrace expects a single destructured object parameter, not two positional args:

export default async function ({ executionId, actionExecutionId }) {

Without the braces, the runtime still only passes one argument into your function — so executionId ends up being the entire context object, and actionExecutionId is undefined. This can throw off execution(executionId) downstream since it's not getting the plain ID string it expects.

see the document - Run JavaScript action for Workflows — Dynatrace Docs

sujit_k_singh_0-1785194619318.png

 

2. predResult['result']

const result = predResult['result'];

exe.result() returns exactly what get_monitoring_config returned it's not automatically wrapped in a result key. Unless that task explicitly does return { result: ... }, predResult already is your JSON payload, and predResult['result'] will be undefined. That matches the symptom you're seeing.

You're also shadowing the result you imported from @dynatrace-sdk/automation-utils by naming a local variable result — worth renaming to avoid confusion later.

Thanks,

Sujit

Dynatrace Professional Certified

Featured Posts