Search code examples
azure-logic-appspower-automatepower-platform

Azure Logic App - Loop to write to SharepointList


I have a bit of a challenge here! I receive data from a Form Response trigger as shown in the code below.

I have quite complex flow behind it already, but in the end, I want it to write data to a sharepoint list. The challenge is that it would need to sometimes loop based on the number of answers given in the form response.

For example, when someone replied "Product Company" (as in example) the Input in the Sharepoint should be as follows :

ReportName UserRole FilterValue User
PTS - WOL Campaign Report Product Company HOP JaneDo@XXX.com
PTS - WOL Campaign Report Product Company ITH JaneDo@XXX.com

How should I start?? I have no clue.. :/

{
    "statusCode": 200,
    "headers": {
        "Pragma": "no-cache",
        "Transfer-Encoding": "chunked",
        "Vary": "Accept-Encoding",
        "Content-Length": "493"
    },
    "body": {
        "responder": "JaneDo@XXXcom",
        "submitDate": "1/20/2022 4:32:08 PM",
        "ra22de8ef4d2744f49662d98f618bb614": "",
        "rb6faae7228c4454d91422175db06cfde": "PTS - WOL Campaign Report",
        "rc456e0fddc9440a09a67cbf979173354": "Product Company",
        "rec611b6290ae48179ad62f7d4f0c7a50": "[\"HOP\",\"ITH\"]",
        "r958deb1b0a9c411a8d8a9ccbed256689": "",
        "r80943943042b414c80c3d56b6cb669e8": "Myself",
        "r35825e12ace649ec964d24a86d851762": "Testing"
    }
}

Solution

  • Try this ...! Insert a Parse JSON action using your payload to generate the schema. There's a button there that says Generate from sample.

    The next action after that should be another Parse JSON step with this as the schema ...

    {
        "type": "array",
        "items": {
            "type": "string"
        }
    }
    

    ... then you want to assign your array property as the content that came from the previous Parse JSON action ...

    Parse JSON

    Underneath that, define a variable that will hold the individual value from the inner array.

    Variable

    ... now underneath that, loop through each item in the newly created array.

    Loop

    Result

    This is the end result, the loop traverses over the two objects that were in the sample you provided.

    Within that loop, you can get all of your other properties and create as many new list items as the array has items.

    Item 1

    Item 1

    Item 2

    Item 2