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

Can we run workflow in loop

heramb_sawant
Organizer

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


14 REPLIES 14

StrangerThing
DynaMight Mentor
DynaMight Mentor

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

Observability Engineer at FreedomPay

AurelienGravier
DynaMight Champion
DynaMight Champion

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 :

AurelienGravier_1-1754580653566.png


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 :

AurelienGravier_2-1754580758854.png

 

Regards Aurélien.

 

 

 

 
Observability consultant - Dynatrace Associate/Pro/Services certified

heramb_sawant
Organizer

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);

}

 

 

https://docs.dynatrace.com/docs/shortlink/workflows-action-javascript#example-using-the-automation-u...

Regards Aurélien

Observability consultant - Dynatrace Associate/Pro/Services certified

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

Observability consultant - Dynatrace Associate/Pro/Services certified

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.

Observability consultant - Dynatrace Associate/Pro/Services certified

Hi ,

Please find the SS for your reference.
heramb_sawant_0-1755674408531.png

workflow 1 has task "run_workflow_1" having input values

heramb_sawant_1-1755674522009.png


results of the task that calls Workflow 2:

heramb_sawant_2-1755675041312.png



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:

AurelienGravier_0-1755676737103.png

 

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

{{ input('language') }} {{ input('topic') }
 

Sources:

Regards

Observability consultant - Dynatrace Associate/Pro/Services certified

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

Featured Posts