azure-logic-apps

Logic apps - how to read 2 rows through an index variable


json input -

{
  "tables": [
    {
      "name": "primaryresult",
      "columns": [
        {
          "name": "startdate",
          "type": "string"
        },
        {
          "name": "enddate",
          "type": "string"
        }
      ],
      "rows": [
        [
          "01/01/2014",
          "31/01/2014"
        ],
        [
          "01/02/2014",
          "28/02/2014"
        ]
      ]
    }
  ]
}

i need to get out put -

[ {"startdate" : "01/01/2014", "enddate" : "31/01/2014"}, {"startdate" : "01/02/2014", "enddate" : "28/02/2014"} ]

need to arrive through index variables

I could able to read columns dates of startdate, enddate in the loops and dont know how to read rows - datas through indexvariable, and i dont want through hardcorded values.


Solution

  • You can use below design which worked for me:

    enter image description here

    then:

    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": {
                "Compose": {
                    "inputs": {
                        "tables": [
                            {
                                "columns": [
                                    {
                                        "name": "startdate",
                                        "type": "string"
                                    },
                                    {
                                        "name": "enddate",
                                        "type": "string"
                                    }
                                ],
                                "name": "primaryresult",
                                "rows": [
                                    [
                                        "01/01/2014",
                                        "31/01/2014"
                                    ],
                                    [
                                        "01/02/2014",
                                        "28/02/2014"
                                    ]
                                ]
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "Compose"
                },
                "For_each": {
                    "actions": {
                        "Select_2": {
                            "inputs": {
                                "from": "@range(0,length(body('Select')))",
                                "select": {
                                    "@{body('Select')?[item()]}": "@items('For_each')?[item()]"
                                }
                            },
                            "runAfter": {},
                            "type": "Select"
                        }
                    },
                    "foreach": "@first(outputs('Compose')?['tables'])?['rows']",
                    "runAfter": {
                        "Select": [
                            "Succeeded"
                        ]
                    },
                    "type": "Foreach"
                },
                "Select": {
                    "inputs": {
                        "from": "@range(0,length(first(outputs('Compose')?['tables'])?['columns']))\r\n",
                        "select": "@first(outputs('Compose')?['tables'])?['columns']?[item()]?['name']"
                    },
                    "runAfter": {
                        "Compose": [
                            "Succeeded"
                        ]
                    },
                    "type": "Select"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {},
            "triggers": {
                "manual": {
                    "inputs": {
                        "schema": {}
                    },
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {}
    }