Run workflows in a loop

Hi,
I have workflow with 4  tasks that run one after another . Currently this workflow task’s various information for particular application , I want to run the same workflow for multiple applications.  How can I run it in loop or is there any workaround.

Regards,
heramb Sawant

Check out running a Workflow from a Workflow (sub-Workflows):  Run workflow action for Workflows — Dynatrace Docs

Hello @heramb_sawant ,

First of all, add a task to generate your applications list.

Afterwards, create a child task and use the Loop Task option by adding the List related to the previous task and use a item variable name :

And finally you can use {{ _.item }} or in case of the Run JavaScript action, you can use loopItem function to access the item in each iteration :

Regards Aurélien.

Hi 
I built 2 workflows

workflow 1 - having  “run workflow” task . In loop task, there is  item variable name “item” and its value is json object i.e. 
[{

“cluster” : “Cluster1”,
“namespace” : “namespace1”

},
{
“cluster” : “Cluster2”,
“namespace” : “namespace2”

}

]

This workflow calling another workflow i.e workflow2.

Here in workflow2 , I am trying to print item values of workflow 1 but getting error in javascript code.

console.log(loopItemValue.value);

error : can not read properties of null(reading 'value)

Please correct me

Hello @heramb_sawant

You should use something like that :

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

export default async function ({ loopItemValue }) {

  // load the execution object using the current loopItemValue
  const exe = await execution(loopItemValue);

  const checkResult = await exe.result('workflow1');

  const json = checkResult['json'];

  // APPELER L'ATTRIBUT NAME
  console.log('Cluster : ', json.cluster);
  console.log('Namespace : ', json.namespace);

}

Regards Aurélien

getting error  in workflow2,

define_application_details:
Uncaught (in promise) 404: Task run_workflow_1 does not exist.

here "run_workflow_1 " is task from workflow 1. I tried with workflow1 names but same error

@heramb_sawant

I’m not sure I fully understand what you mean.

You’re talking about a “workflow 1” and a “workflow 2,” whereas I’m referring to “tasks” within the same workflow.

In my case, you run check-result on the previous task name, which returns the JSON.

Regards

I am trying to  call workflow 2 from workflow 1.

Workflow 1 has task that calls workflow 2. This task also has loopitem i.e. “item” having json object as value.
Then trying to access this loopitem values in workflow 2 but getting error.

Any help will  be appreciated.

Ok, so to assist you further,

Export your workflow as a template (make sure it doesn’t contain any personal data),

AurelienGravier_0-1755590235340.png

Or Take a screenshot of Workflow 1 and another screenshot of the results of the task that calls Workflow 2.

Hi ,

Please find the SS for your reference.

workflow 1 has task “run_workflow_1” having input values

results of the task that calls Workflow 2:

I  want to receive input values in workflow 2.

Ok, I understand your need better.

I have never experimented with this, but in my opinion you need to add {{ _.item }} in your input:

And you must use the input() expression in the sub-workflow :

{{ input(‘language’) }} {{ input(‘topic’) }

Sources:

Regards

how to use this {{ input(‘language’) }} {{ input(‘topic’) } in javascript task of sub workflow i.e workflow2

any help regarding receiving input values in JS task would be appreciated.

Hi,
Any help to receive input values from one workflow to another workflow