Logic App inline code in foreach loop

sdnd2000 41 Reputation points
2023-07-26T17:32:10.5366667+00:00

Hi, I am trying to get the input inside the foreach loop for inline code, how can I do that?

Sample output Json from "select" step:

{
    "body": [
        {
            "Header1": "1",
            "Header2": "21",
            "Header3": "31",
            "Header4": "41",
            "Header5": "51"
        },
        {
            "Header1": "2",
            "Header2": "22",
            "Header3": "32",
            "Header4": "42",
            "Header5": ""
        },
        {
            "Header1": "3",
            "Header2": "23",
            "Header3": "33",
            "Header4": "43",
            "Header5": "53"
        }
    ]
}

User's image

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,184 questions
{count} votes

Accepted answer
  1. Sonny Gillissen 3,351 Reputation points
    2023-07-27T20:33:05.9266667+00:00

    Hi sdnd2000

    Thank you for reaching out on Microsoft Q&A!

    Since you’re already in the for each loop, you want to the current iteration instead of referring to the select action (which holds the entire array). For this you need to add the foreach loop to the Actions using the parameters to explicitly load the contents:

    Screenshot showing the Inline Code action and "Actions" parameter selected.

    In the appearing box now add the name:

    For_each

    Within your inline code block you can now refer to the attributes by selecting them like this:

    var text = workflowContext.actions.For_each.foreach.Headers1

    Please click “Accept answer” if you find this helpful. Feel free to drop additional queries in the comments below!

    Kind regards,

    Sonny


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.