0

I have a problem with a flow, there are errors at the 'Create Folders' stage. I'm getting a bad request error message (see the Flow Errors header below).

The flow is meant to use an array that contains the name values for 8 sub-folders. The flow is triggered by a new folder being created, this is then meant to make the 8 sub-folders.

Research so far

I've read a lot of guides including this one on the MS Powerusers site which get me part way to what I want to do. I've used this to configure the Trigger Conditions:

IsFolder eq True (only kick-off the flow if a new folder is created).

Don't kick off the flow if the folder name equals e.g. 1. Pre Action Protocol correspondence

Flow Errors

error picture - problem with the Apply to All and Create Folder steps

There are two errors, but the 'Apply to All' error says "An action failed. No Dependent Actions Succeeded":

error picture

Create new folder - bad request error message:

create folder error message

Other info on the Flow, purpose of each step

As you see there are 8* sub-folders:

Folder names:

  1. Pre Action Protocol correspondence

  2. Pleadings, Order and Applications

  3. Experts

  4. Witness Statements

  5. Documents

  6. Internal correspondence

  7. External correspondence

  8. Counsel

*I've found that there is a hard limit of 10 trigger conditions. In order to prevent the flow being stuck in an endless loop, I was able to list the sub-folder names of 1- 8 in order to prevent the flow being triggered again by the creation of sub-folders.

(I have even more 'lower-level' folders too, but they'll be created manually, as I have insufficient trigger conditions to prevent the flow becoming struck in a folder creation loop).

picture showing trigger conditions - must be 'IsFolder' equals True and it excludes the names of any sub-folders from triggering the Flow

The Initialise Variable step creates an array with the 8 sub-folder names:

The Parse JSON does this:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "SubFolder": {
                "type": "string"
            }
        },
        "required": [
            "SubFolder"
        ]
    }
}

The Apply to All does this:

{
  "type": "Foreach",
  "foreach": "@body('Parse_JSON')",
  "actions": {
    "create_new_folder": {
      "type": "OpenApiConnection",
      "inputs": {
        "parameters": {
          "dataset": "https://Contoso.com/sites/T_Legal",
          "table": "a33070d9-9a00-45cc-8886-97d2d0602c00",
          "parameters/path": "Disrepair Claims/@{triggerBody()?['{Name}']}/@{body('Parse_JSON')}"
        },
        "host": {
          "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline",
          "connection": "shared_sharepointonline",
          "operationId": "CreateNewFolder"
        }
      },
      "metadata": {
        "operationMetadataId": "55385add-fc3f-4510-a591-ca632bf95992"
      }
    }
  },
  "runAfter": {
    "Parse_JSON": [
      "Succeeded"
    ]
  },
  "metadata": {
    "operationMetadataId": "d4cebc2c-7940-4195-8c98-8e13fce335ab"
  }
}

Folder creation step:

{
  "type": "OpenApiConnection",
  "inputs": {
    "parameters": {
      "dataset": "https://Contoso.com/sites/T_Legal",
      "table": "a33070d9-9a00-45cc-8886-97d2d0602c00",
      "parameters/path": "Disrepair Claims/@{triggerBody()?['{Name}']}/@{body('Parse_JSON')}"
    },
    "host": {
      "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline",
      "connection": "shared_sharepointonline",
      "operationId": "CreateNewFolder"
    }
  },
  "metadata": {
    "operationMetadataId": "55385add-fc3f-4510-a591-ca632bf95992"
  }
}

Other Info

FYI - the value 'Disrepair Claims' is the name of an MS Teams channel.

Screenshot of Teams name and channel

This Stack Exchange question is semi-similar to mine, but I don't want to use an Excel file for the sub-folder names.

Update following Ganesh's answer

This is a Teams site which has pre-defined channels, so I have an extra layer compared to your answer - so yes, you were right to suspect I might have a slightly different set up.

Because I needed the subfolders to be created within the new channel, it means the trigger conditions need adjusting to prevent the folder creation command becoming stuck in an infinite loop. I still don't understand the fields and values Power Automate uses to adjust this myself, though I understand why its needed.

screenshot of the Legal Teams site & channels

Update following Jan 4th comments

Here's how the create new folder action is configured:

Picture of the create new folder action

The 'Name' field I see is listed in Dynamic Content under the (Sharepoint) When an item is created or modified section:

enter image description here

BTW - I'm working on a slight variant Flow which uses a manual trigger instead of the 'when a new folder is created' trigger. It's simpler this way to prevent SP/Power Automate going crazy creating 1,000s of folders!

I still find it difficult to point Power Automate to the correct location, I can't seem to force it to create the subfolders within the 'Project 1' location - it creates them at the same level as Project 1 instead of inside it. (I could post that as a separate question though, maybe it's an MS Teams issue rather than a Power Automate issue)

12
  • Does this question qualify for the longest ever?
    – Tally
    Dec 11, 2023 at 14:23
  • 1
    Well, I have spent an hour for this and tried to add the "longer" answer for your question :D . Let me know if it works for you. Dec 20, 2023 at 9:16
  • 1
    Let me know if you are not creating the main folders (like Project 1 in my example below) at the top level AND you are creating the subfolder for each project and then want to create the subfolders defined in array inside the project folder. In that case, you will have to tweak the expression used in "Create new folder" action slightly (maybe I am confusing you with this comment). Dec 20, 2023 at 9:29
  • 1
    Let me know if it is working for you now or you need any further help on this? You can add one more trigger condition to run the flow only if the folder is created inside "Disrepair" folder based on folder path from trigger outputs and you are right about adding folder name (like Disrepair/) in create new folder action. Dec 21, 2023 at 10:47
  • 1
    (I'm on holiday but will accept this as an answer - I wouldn't want you to lose the bounty after all the time you spent on it, most appreciated! I'll try again once I'm back)
    – Tally
    Dec 25, 2023 at 21:46

1 Answer 1

2
+100

Here is the working flow I just created and tested:

enter image description here

Run history output:

enter image description here

Document library output - created folders:

enter image description here


Flow Details:

Trigger conditions:

I have added similar trigger conditions you have used, like:

enter image description here

You are correct about maximum 10 trigger conditions are allowed. However, if you want to check for more than 8 folder names, you can merge the folder name conditions using or() like:

@not(or(equals(triggerOutputs()?['body/{Name}'], 'Counsel'),equals(triggerOutputs()?['body/{Name}'], 'Experts')))

Initialize variable - arrSubfolders Value:

[
  {
    "SubFolder": "Pre Action Protocol correspondence"
  },
  {
    "SubFolder": "Pleadings, Order and Applications"
  },
  {
    "SubFolder": "Experts"
  },
  {
    "SubFolder": "Witness Statements"
  },
  {
    "SubFolder": "Documents"
  },
  {
    "SubFolder": "Internal correspondence"
  }
  ,
  {
    "SubFolder": "External correspondence"
  }
  ,
  {
    "SubFolder": "Counsel"
  }
]

Parse JSON Schema:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "SubFolder": {
                "type": "string"
            }
        },
        "required": [
            "SubFolder"
        ]
    }
}

Apply to each input: Body from Parse JSON output (dynamic content)

Create new folder - Folder Path:

@{triggerOutputs()?['body/{Name}']}/@{items('Apply_to_each')['SubFolder']}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.