Use Power Automate to create a folder in SharePoint with link back to Microsoft Lists

In this blog post I will out line how Power Automate can be used to create a folder in a SharePoint document library and then store the link to the newly created folder inside of Microsoft Lists. I have used this pattern numerous times for business processes where transactional metadata and document storage are required. For example, a case management list stores the business process data and the folder stores the supporting documents.

I am using a list called “Exchange Agreements” in this blog post. You can replicate this Exchange Agreements using the my spreadsheet (see below) and these instructions: Microsoft Lists: new list using an existing Excel spreadsheet

Let’s start by adding a new “Hyperlink” column to the Exchange Agreements list called “FolderLocation”.

Create a column

Create a new Flow from by clicking “Automate” > “Power Automate” > “See your Flows”.

See your Flows

Create a new “Automated – from blank” Flow.

New automated Flow

Provide a name for the Flow i.e. “Exchange Agreements – New”; select the “When an item is created” SharePoint trigger and then click “Create”.

SharePoint when an item is created

Set the “Site Address” and “List Name” to you target site and list.  

SharePoint when an item is created

Click “New step”, search for “Variable” and select the “Initialize variable” action. Set the “Name” to “varFolderName” and “Type” to “String”.

“Value” should be set to something unique, readable and short. In my demo, I combine school name and exchange type for a value of “University of South Australia (Undergraduate Programs)”.

Power Automate expressions and the concat function work well in these situations. Here is the expression I use:

concat(triggerOutputs()?['body/Title'], ' (', triggerOutputs()?['body/ExchangeType/Value'], ')')

Initialize variable

Click “New step”, search for “SharePoint” and select the “Create new folder” action.

Set the “Site Address”, “List or Library” to you target site and document library, and “Folder Path” to “varFolderName”.

Create new folder

At this point the folder has been created and now we have to update the list with the URL path to the folder.

Click “New step”, search for “SharePoint” and select the “Send an HTTP request to SharePoint” action.

Set the “Site Address” and “List Name” to you target site and list. 

Also set:

  • “Method” to “POST”
  • “Uri” to “_api/web/lists/GetByTitle(‘Exchange‘)/items(ID)
    • Where ‘Exchange’ is the list name and ID is the “ID” from the SharePoint “Create new folder” action
  • “Headers” – switch to text – to:
    {
    “Content-Type”: “application/json;odata=verbose”,
    “X-HTTP-Method”: “MERGE”,
    “IF-MATCH”: “*”
    }
  • “Body” to:
    {‘_metadata’: {‘type’:’SP.Data.ExchangeListItem’},’FolderLocation‘: {‘Description’: ‘varFolderName‘, ‘Url’: ‘LinkToItem‘}
    }
    • Where Exchange is the list name; FolderLocation is the column name; varFolderName is the variable and LinkToItem comes from the “Create new folder” action.

My completed Flow looks like the image below:

My completed FLow

Save your Flow and test by submitting a new item to your list. If all goes well the new folder will be created and a link to the folder will be added to the list item.

Folder created
List item with folder link.

This pattern can be beneficial for large volume lists and folders. The folder location URL serves as a simple pointer to the supporting documents and negates the need for the user to search or navigate to the folder.

Thanks for reading.

NY

30 thoughts on “Use Power Automate to create a folder in SharePoint with link back to Microsoft Lists

  1. Great and valuable blog which will add huge business process benefits!
    Question – off topic – if you have a Microsoft List created can you adjust power automate to send emails to line managers and customers so for example power automate can send a bulk email which includes 3 of 4 items in the list which require them to action?
    At the moment I have setup power automate to send emails per individual item. Managers want 1 email alert not 3 or 4 emails per item on the list.

    Like

    1. Hi Amardip,

      Yes, you can set up a message with multiple items. The key to the solution is that the message body needs to be compiled before the send mail message action executes. This sounds like a great idea for a future blog post.

      Thanks for reading!

      Norm

      Like

  2. Hi, this is very helpful, but I am getting stuck on the last step. I am getting the error “An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.” I did exactly what was specified above. I’m not able to post a screenshot here it seems…

    Like

    1. Hi MarRayn,

      Check that the ExchangeType is populated with a valid entry. The ExchangeType is part of the variable definition and ultimately becomes the folder-link name.

      I’m happy to help further and thanks for reading.

      NY

      Like

  3. Thank so much for your reply! In my version, I had to replace “exchange type/value” with “title”. So, my variable is: concat(triggerOutputs()?[‘body/ID’],’_’,triggerOutputs()?[‘body/Title’]). I was able to create a file name that is “ID_Title”.

    I’ve been able to narrow down the issue to something wrong with the Uri or body of the “send http request to SP”:

    Body:
    {‘_metadata’: {‘type’:’SP.Data.Sales-Training-Development-RequestListItem’},’Link1′: {‘Description’: ‘@{variables(‘varFolderName’)}’, ‘Url’: ‘@{outputs(‘Create_new_folder’)?[‘body/{Link}’]}’}
    }

    The list name is “Sales-Training-Development-Request”. “Link1” is a hyperlink column in my list. I’ve also tested with a second column, “Link2”, which is a one-line text field and wasn’t successful with either.

    I was also having some trouble with my Uri, but I thought I managed to fix it:

    _api/web/lists/getbytitle(‘Sales-Training-Development-Request’)/items(‘@{outputs(‘Create_new_folder’)?[‘body/ID’]}’)

    Thank you for any insight you can provide! I appreciate you taking a look at this!

    MR

    Like

    1. Hi MarRayn,

      You are missing an underscore on metadata. “_metadata” should be “‘__metadata”.

      Test and let me know how you make out.

      NY

      Like

  4. Hi Norm,

    Trying to do as described.

    I am having trouble getting the API call Uri” to work
    The expression “web/lists/GetByTitle(‘MDSNET21_CUSTOMER_PROJECTS‘)/items(99)” is not valid.
    clientRequestId: 4b44b4c6-9e66-439d-8651-dac79c3ca318
    serviceRequestId: 5ba8b09f-5068-2000-9324-ede1db259587

    Where MDSNET21_PROJECT_LIST is the list where i want to add the URL and the ID is the correct one
    I Cannot find out why flow fails

    Question : when someone changes the name of the list to something else, it will not work anymore, because the name is hardcoded?

    Like

    1. Hi Wilfried,

      Check your single quotes and ensure that they are ‘ and not ‘. WordPress is messing up my code formatting.

      Thanks for reading!

      NY

      Like

  5. Hello! This looks like what I need but I need to both create the list AND the folder structure at the same time. Since I’m not that experienced at Power Automate, do you have any particular guidance you can provide or pointers I need to keep in mind.
    Thank you.

    Like

      1. Thanks you for your very kind reply, Norm.

        I have an excel list of 600 topics that I’d like to import. Of course, the new list imports fine and has some metadata I’d like to keep. Account name; account number; owned by; classification etc.

        Whether during the import OR afterward, I need to add the new folders to the document library and then update the imported list with the link. I’d like to concatenate the account name and account number as the new folder name.

        I read the instructions and they are Greek to me. Do have have an example of carrying out such a task or how shall we proceed?

        Like

      2. Hi Cindy,

        This is definitely possible and the Flow pattern in this blog post can be used as a reference point. The major difference is you are running this Flow in batch and will require a different trigger (i.e. Scheduled) and a listing or rows to process (i.e. SharePoint get items and a loop).

        I’m happy to help you with this Flow if you like.

        NY

        Like

  6. Hi – I tried your “Send an HTTP request to SharePoint” but could not get it to work. I found a much easier way with “Update item” – so simple it was crazy after spending about 3 hours trying your way.

    Like

    1. Hi Fiona,

      Sorry to hear that you couldn’t get it to work. The syntax is very particular and I know I have had similar “3 hours trying”. My preference for this Flow would have been to use the Update item action but at the time of developing this pattern adding a hyperlink with a description was not supported and as far as I know, it is still not supported. How did you do it?

      Thanks for reading!

      NY

      Like

      1. Hi Norm,

        I followed your steps to where you said “At this point the folder has been created and now we have to update the list with the URL path to the folder.” I then used Update Item for my list and then used the Dynamic Content from the Create Folder step to add the URL for the folder to my list which had a column set up for the URL link.

        Like

      2. Hi Fiona,

        Were you able to add a link description? Last I checked that wasn’t an option. In my Flow pattern, the link to the list item is the school name.

        Thanks.

        NY

        Like

      3. Hi Norm,

        I didn’t need to add a link description as the description was in the Description column of the List.

        Like

  7. Hi Yassine,

    After I had created the folder with VarFolderName being I then simply created another variable for the link. So it was just a matter of getting the same naming logic for creating the folder as creating the URL.

    Name: SupportDocsLink
    Type: String
    Value: https://tenantname.sharepoint.com/sites/Contracts/SupportingDocs/

    And then used the output from this step and added to the “hyperlink” column in the list item.

    Hope this helps.

    Like

  8. Hello Norm,

    thanks for the good article.
    I would like to create the new folder, in a subfolder of “Documents”, something like: Documents/General/Newfolder.
    Is this possible?

    Thanks

    Like

    1. Hi Simone,

      Yes, that is possible and can be as simple as adding /General to the path in the create folder action. If you need to do this dynamically (i.e. Teams) then it’s a bit more work. Check out this post to see how involved it can be for dynamic Teams SPO site URL retrieval.

      Thanks for reading!

      NY

      Like

      1. Thanks Norm. That´s solved.
        I can create the folder but I get stack on the link.

        the expression “web/lists/GetByTitle(‘PipelineSRC‘)/items(91)” is invalid.
        clientRequestId: 2d5f4e2e-a518-45af-b3d9-9e9f3c98a63b
        serviceRequestId: db5fc49f-b056-b000-fd7b-199745ba29fc

        “errors”: [
        “-1”,
        “Microsoft.SharePoint.Client.InvalidClientQueryException”

        This is the Input:
        _api/web/lists/GetByTitle(‘PipelineSRC‘)/items(@{outputs(‘Create_new_folder’)?[‘body/ID’]})

        PipelineSRC: is the list name.

        Like

      2. Hi Simone,

        Assuming there are no syntax errors, especially with “__metadata” and single quotes, check the internal list name by adding this to the URL:

        /_api/Web/Lists/GetByTitle(List Name here’)?$select=ListItemEntityTypeFullName

        Let me know how you make out.

        NY

        Like

  9. Hello again Norm,
    Still no chance at the moment.
    I changed “_metadata” to “__metadata” and use this ‘ everywhere.
    I have added the string as you have proposed and I get this:

    The expression “web / lists / GetByTitle (‘PipelineSRC’) / items (139) / _ api / Web / Lists / GetByTitle (PipelineSRC ‘)” is not valid.
    clientRequestId: 0f2d29d6-5629-4baf-b334-42b2fffefbc0
    serviceRequestId: f1dbc49f-c009-b000-fd7b-17bfc4dc85d4

    This is the input:
    {
    “host”: {
    “connectionReferenceName”: “shared_sharepointonline”,
    “operationId”: “HttpRequest”
    },
    “parameters”: {
    “dataset”: “https://xxxxxxxxxxxxxxx”,
    “parameters/method”: “POST”,
    “parameters/uri”: “_api/web/lists/GetByTitle(‘PipelineSRC’)/items(139)/_api/Web/Lists/GetByTitle(PipelineSRC’)?$select=ListItemEntityTypeFullName”,
    “parameters/headers”: {
    “Content-Type”: “application/json;odata=verbose”,
    “X-HTTP-Method”: “MERGE”,
    “F-MATCH”: “*”
    },
    “parameters/body”: “{‘__metadata’: {‘type’:’SP.Data.PipelineSRCListItem’},’Folder’: {‘Description’: ’29_folder name’, ‘Url’: ‘https://xxxxxxxxxxx//29_folder name’}\n}”
    }
    }

    Any input would be appreciated.

    Like

  10. Hi Norm, great article! Are you perhaps aware if it is possible to create a link for accessing the folder through the teams tab? I’m having a list inside a teams channel, where creating item triggers a PA flow that creates a folder in the library and then creates a Sharepoint folder sharing link for that folder and pastes it back into the list. The problem is it’s a link to a folder in a sharepoint site instead to the same folder through a teams tab. The thing is I need guest users to be able to work on list items and documents through teams UI, and switching to Sharepoint is confusing for them and requires additional fiddling with access rights. Am I asking too much from the big MS? 🙂

    Like

    1. Hi Alijaz,

      Thanks for the feedback, I appreciate it. You pose a great question. The out-of-the-box functionality does not allow the folder to be opened in the Teams Files context BUT I wonder if this could be created. Let me think about this one and explore options! More to follow.

      Thanks for reading!

      NY

      Like

Leave a Reply to Wilfried Montald Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s