This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Multiple actions in one loop based on the current item

Hi,

what I am trying to do is a workflow that at some point needs to loop over a list of dictionary items. In this loop I need to start several actions using values from the current item as input. As the last step of one iteration of the loop I want to use all results in an final action.

I created a picture for better understanding:

So far I was not able to identify a solution. I tried multiple actions in a with statement but it looks like only the last action definition is used.
Also publishing the current item value and starting another action via next was not possible as the next statement is only executed once after all iterations are done.

Maybe subworkflow might be a solution, but I wanted to ask you for the best approach. It would also be nice to have it in one workflow.

Any idea is appreciated.

Thanks.

@wingi You can make another workflow with those “several actions” in it, then your main workflow can use with-items to invoke that workflow once per item in your dictionary.

Does this make sense?

yes this works so far. Just wanted to know if there is another possibility as well. There might be some use cases where it is easier to have it in one workflow, to use several variables without passing them force and back.

Hi,

during further development I have a follow-up question.
How can I go on with the WFL after all loops are done like shown in my flow chart?
For now the WFL goes on after every iteration of the loop. What I want to achieve is that “other_things” and following tasks are only executed once.
“Join: all” was not working, I can imagine it is because of there are no different branches before.

My current WFL:

tasks:
   Loop_over_hosts:
    action: my_pack.subworkflow
    with:
      items: <% ctx().Hosts %>
      concurrency: 1
    input:
      ...
    next:
      - when: <% suceeded %>
        do: other_things


  other_things:
    action: st2.kv.set
    input:
      key: some_key
      value: "foo"