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.

Orquesta publish item into context from loop

I have a workflow that is looping using a json object that has an array of json objects (devices). I wish to publish the item into the context as variable foo, as follows:



render_template:
with:
items: device in <% ctx(mop_automation_object).devices %>
concurrency: 1
action: mop_automation.render_template
input:
device: <% item(device) %>
next:
- when: <% succeeded() and … %>
publish:
- cli_templates: <% result().result %>
- foo: <% item() %>
do: cli_workflow

cli_workflow:
action: mop_automation.mop_automation_cli_workflow
input:
device: <% ctx().foo %>
templates: <% ctx().cli_templates %>
skip_approval: false
next:
- when: <% succeeded() %>

It seems to be empty, am i doing something wrong, or is that not possible.

@techdiverdown Can you format your code block using Markdown? It’s really difficult to read and parse if it’s not formatted.

tasks:
    render_template:
        with:
        items: device in <% ctx(mop_automation_object).devices %>
        concurrency: 1
    action: mop_automation.render_template
    input:
        device: <% item(device) %>
    next:
        - when: <% succeeded() and … %>
          publish:
            - cli_templates: <% result().result %>
            - foo: <% item() %>
        do: cli_workflow

    cli_workflow:
    action: mop_automation.mop_automation_cli_workflow
    input:
        device: <% ctx().foo %>
        templates: <% ctx().cli_templates %>
        skip_approval: false
    next:
        - when: <% succeeded() %>

Double check that your indentation is correct, but in your example it looks like you’re constructing foo from all of the items in ctx(mop_automation_object).devices. Is there any reason you can’t just pass that straight through like so?

tasks:
    render_template:
        with:
            items: device in <% ctx(mop_automation_object).devices %>
            concurrency: 1
        action: mop_automation.render_template
        input:
            device: <% item(device) %>
        next:
            -   when: <% succeeded() and … %>
                publish:
                    - cli_templates: <% result().result %>
                    - foo: <% ctx(mop_automation_object).devices %>
                do: cli_workflow

    cli_workflow:
        action: mop_automation.mop_automation_cli_workflow
        input:
            device: <% ctx().foo %>
            templates: <% ctx().cli_templates %>
            skip_approval: false
        next:
            - when: <% succeeded() %>

If you want to modify each device in mop_automation.render_template before you publish it to foo, then you’ll need to use result().result along with .select(), .flatten(), .where(), etc. to build what you would like.

1 Like