Search code examples
arraysloopsjiraelementazure-logic-apps

Logic app loop through all elements on the array and add it to the body/description


Actually I don't know if this will work. But I have long array with a lot of elements, I need to display all element in order on the body/description of Jira ticket without writing it manually (example: outputs('Compose')?[0] outputs('Compose')?[1] outputs('Compose')?[2] ). Is there anyway to do it using loop? or any other method?

Note: I don't want it to be as paragraph I need it the same as the array listed.

Example array:

[ 'first element', 'second element', 'third element', ]

printed/displayed format:

first element

second element

third element


I tried using loop but don't understand it.

please consider that I'm new to the Logic App or any other technologies with the same idea


Solution

  • There are ways which we can perform data operations such as:

    • Line by line
    • Spaces

    Option 1: Line by line

    Firstly, I have initialized a variable as below:

    enter image description here

    Then used Join (Data Operations) as below:

    enter image description here

    (here I just clicked Enter in Join with )

    Output:

    enter image description here

    enter image description here

    Code view:

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Initialize_variable": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "emo",
                                "type": "array",
                                "value": [
                                    "rithwik",
                                    "bojja",
                                    "chotu"
                                ]
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "InitializeVariable"
                },
                "Join": {
                    "inputs": {
                        "from": "@variables('emo')",
                        "joinWith": "\n"
                    },
                    "runAfter": {
                        "Initialize_variable": [
                            "Succeeded"
                        ]
                    },
                    "type": "Join"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {},
            "triggers": {
                "manual": {
                    "inputs": {
                        "schema": {}
                    },
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {}
    }
    

    So now you can use the output of Join(body('Join')

    Option 2: Spaces

    If you keep space in Join you will get ouput as below:

    enter image description here

    Output:

    enter image description here

    Code view:

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Initialize_variable": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "emo",
                                "type": "array",
                                "value": [
                                    "rithwik",
                                    "bojja",
                                    "chotu"
                                ]
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "InitializeVariable"
                },
                "Join": {
                    "inputs": {
                        "from": "@variables('emo')",
                        "joinWith": " "
                    },
                    "runAfter": {
                        "Initialize_variable": [
                            "Succeeded"
                        ]
                    },
                    "type": "Join"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {},
            "triggers": {
                "manual": {
                    "inputs": {
                        "schema": {}
                    },
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {}
    }