Search code examples
azureazure-logic-appsazure-logic-app-standard

Logic app standard not refreshing variable while working with SharePoint


I'm working on a Stateless flow in a Standard Logic app. The flow works like this:

  1. Get the files from the SharePoint folder
  2. Loop them through
  3. Create a GUID for each file
  4. Upload the file to a temp folder based on the GUID generated in Step 3. I am using a variable called tempFolderId to store the value of the GUID.

However, I am facing a strange issue. If I have (say) 2 files in the folder, tempFolderId gets populated with a different Guid for each file, that works fine. But when I try to upload the file using tempFolderId, sometimes it uses the correct value of the tempFolderId (mostly when it runs for the first time), at other times, it uses the same value of tempFolderId in both cases (even tempFolderId in the assignment above shows 2 different values each time).

  {
  "type": "SetVariable",
  "description": "declared this as tempFolderId variable was not getting refreshed due to some reason",
  "inputs": {
    "name": "tempFolderName",
    "value": "@variables('tempFolderId')"
  },
  "runAfter": {
    "HTTP-upload_file": [
      "SUCCEEDED"
    ]
  }
}

The compose action (where I build up the final payload also contains the same GUID) like this:

[
  {
    "TempFolderId": "030a9827-c5d2-4892-8c25-f12d7c6ba0a1",
  },
  {
    "TempFolderId": "030a9827-c5d2-4892-8c25-f12d7c6ba0a1",
  }
]

A screenshot of the flow is attached (note: the tick mark shows the value is updated correctly each time within the loop, 'X' shows that the updated value is not being passed.

enter image description here

Am I missing something?


Solution

  • Your problem is, you're using a variable to set the GUID and your For each will be running in parallel, you need to turn that off.

    Note: My screenshots are consumption but the premise is the same.

    Flow 1

    Concurrency

    Variables are available globally and because For each is running in parallel, it's setting it for each concurrent run and therefore, it can be the same when it gets to the step after you set it.

    It's a bit tricky but at the end of the day, if you set the concurrency to 1 (as shown) then it will work for you.

    Alternatively, don't use a variable, use a Compose, I believe (90% sure) that too will overcome your issue.