Add attachments from Forms to Microsoft Lists using Power Automate (UPDATED)

Note: The “Get file content using path” and “Apply to each – Add attachment” actions have updated from my original post to correct an issue where the content from multiple attachments was being duplicated.

I added a check “Condition” on the length of the Associated files from MS Forms to ensure that attempts to add attachments to the list item only occur when the responses included uploaded files.


In my previous blog post I outlined how Power Automate can be used to get responses from Microsoft Forms into Microsoft Lists. As a follow up to that post, I will show how to add attachments from Forms to Lists using Power Automate. See my previous blog post for the form, list and Flow build.

From Power Automate, click “New step”, search for “Control” and select the “Condition” action. The Condition action will check for the existence of attachments in the Forms response.

  • Set the left “Choose a value” to the following expression: length(Associated files). Where “Associated files” is Dynamic content from “Get response details”.
  • Set the condition to “is greater than”
  • Set the right “Choose a value” to “0”.

In the “If yes” branch, click “New step”, search for “Data Operation” and select the “Compose” action. This action will generate the required JSON schema needed to parse the attachment JSON.

  • Set “Inputs” to “Associated files” from the Forms “Get response details” action.

Test the Flow and when complete expand the “Compose” step and copy the Outputs.

Compose action output

In the “If yes” branch, click “New step”, search for “Data Operation” and select the “Parse JSON” action. This action will extract the attachment metadata.

  • Set “Content” to “Associated files” from the Forms “Get response details” action.
  • Click “Generate from sample” and paste the “Compose” outputs into “Schema”.
Parse JSON

In the “If yes” branch, click “New step”, search for “Data Operation” and select the “Compose” action. Power Automate will automatically add a “Apply to each” loop.

  • Set “Inputs” to “name” from the “Parse JSON” action.

In the “If yes” branch, click “New step”, search for “Control” and select the “Apply to each” action. This action will allow us to loop through all of the form response attachments and attach them to our list item.

  • Set “Inputs” to “Body” from the “Parse JSON” action.

In the “If yes” branch, click “New step”, search for “OneDrive for Business” and select the “Get file content using path” action. This action will extract the attachment content.

  • Set “File Path” to your Forms attachment location, i.e. “/Apps/Microsoft Forms/Issue tracker/Question/” and add “name” from the “Parse JSON” action.
OneDrive for Business - Get file content using path action

Note: Forms stores attachments in your OneDrive under “/Apps/Microsoft Forms/form name i.e. “Issue tracker”/Question/”.

In the “If yes” branch, click “New step”, search for “SharePoint” and select the “Add attachment” action.  

  • Set the “Site Address” and “List Name” to you target site and list.
  • Set “Id” to “ID” from the previous “Create item” action.
  • Set “File Name” to “name” from the “Parse JSON” action.
  • Set “File Content” to “File content” from “Get file content using path” action.
SharePoint Add attachment action.  

My completed Flow looks like the image below.

Save your Flow and test by submitting a new item from the “Issue tracker” form. If all goes well your Forms submission will be stored in Microsoft Lists and the attachments will be added to the List entry.

List entry with attachments.

Forms is another excellent tool for citizen developers in the Microsoft 365 toolbox. Getting Forms response data and attachments into Microsoft Lists provides so many opportunities for business process automation using Power Automate without relying on “traditional” IT.

Thanks for reading.

NY

48 thoughts on “Add attachments from Forms to Microsoft Lists using Power Automate (UPDATED)

  1. Hi Norm, thanks for the walkthrough but just have one issue. It seems to work with all file types except for PDFs. The flow completes successfully and i see the attachment uploaded but when i try to look at the attachment, it says ‘Failed to load PDF document.’

    Like

    1. Hi Isac,

      This is not what I would have expected. Is the attachment a standard PDF or one with special bookmarks that require the Adobe PDF client to open? Does the attachment open with the OneDrive/SharePoint file viewer?

      Thanks for reading!

      NY

      Like

      1. Hi Norm,

        I figured why this is happening. I’ve set my MS Forms to allow the user to upload multiple attachments. It seems like the PARSE JSON and compose action are able to recognise and output the two attachments but i believe the formula inputted in the action ‘get file content using path’ (e.g. /Apps/Microsoft Forms/Issue tracker/Question/first(body(‘Parse_JSON’))?[‘name’]) only extracts the first attachment.

        Please correct me if i am wrong but if not, would you be able to suggest how to accommodate for multiple attachments?

        Thanks!
        Isac

        Like

  2. Hi Isac,

    Let me dig into this further. Adding multiple attachments should be possible.

    I’ll be in touch.

    NY

    Like

  3. Hi,
    I’m using the same logic to add attachment but I’m facing an issue with multiple attachment.
    In fact, the list displays multiple documents but the “get file content using path” step is reading the first name (first(body(‘Parse_JSON’))?[‘name’])
    That’s why it doesn’t worj for me.
    Any suggestion would be veray appreciated 😉

    Thanks

    Like

  4. Hello,
    very interesting post
    i’m using this logic in & current flow but I’m facing issues to have it working with several attachments

    in fact, I can see both attachments in my sharepoint item but the “Get file content using path” is not working.
    I guess it’s normal because we use the expression first(body(‘Parse_JSON’))?[‘name’]
    So it’s loading only the first name of the body

    I didn’t find a way to loop correctly.

    Any suggestion would be highly appreciated 🙂

    thxs

    Like

    1. Hi Thomas,

      The Flow does work with multiple attachments. WordPress will sometimes convert single quotes ‘ to ’. Update: first(body(‘Parse_JSON’))?[‘name’] to first(body(‘Parse_JSON’))?[‘’name’].

      Thanks for reading!

      NY

      Like

  5. Thanks for your reply. It doesn’t work for me. And I can’t apply your recommendation because it tells me the expression is invalid.

    Here is the step above where I Parse the JSON .
    The issue is that the file path use twice the same name :\Apps\Microsoft Forms\Demande d’analyse – Saint Fons (Copie)\Données Sécurité Veuillez déposer la FDS du produ\FDS_Thomas LORGE 2.pdf

    instead of \Apps\Microsoft Forms\Demande d’analyse – Saint Fons (Copie)\Données Sécurité Veuillez déposer la FDS du produ\receipt train to airport_Thomas LORGE.pdf

    [
    {
    “name”: “FDS_Thomas LORGE 2.pdf”,
    “link”: “https://elkem-my.sharepoint.com/personal/thomas_lorge_elkem_com/Documents/Apps/Microsoft%20Forms/Demande%20d%27analyse%20-%20Saint%20Fons%20(Copie)/Donn%C3%A9es%20S%C3%A9curit%C3%A9%20%20Veuillez%20d%C3%A9poser%20la%20FDS%20du%20produ/FDS_Thomas%20LORGE%202.pdf”,
    “id”: “01NVQRYGWYS2JFMTOAPRA3X7NOKBZLKYAF”,
    “type”: null,
    “size”: 1818360,
    “referenceId”: “01NVQRYGSWLO2ZLARLYBBYFTTKOGLGMC2N”,
    “driveId”: “b!da_GQCGNTU-TpCq0a75y0fKw_skVS0xBqz7NHiYKvrzmRuCsFE47Q7RDO2bruoQi”,
    “status”: 1,
    “uploadSessionUrl”: null
    },
    {
    “name”: “receipt train to airport_Thomas LORGE.pdf”,
    “link”: “https://elkem-my.sharepoint.com/personal/thomas_lorge_elkem_com/Documents/Apps/Microsoft%20Forms/Demande%20d%27analyse%20-%20Saint%20Fons%20(Copie)/Donn%C3%A9es%20S%C3%A9curit%C3%A9%20%20Veuillez%20d%C3%A9poser%20la%20FDS%20du%20produ/receipt%20train%20to%20airport_Thomas%20LORGE.pdf”,
    “id”: “01NVQRYGSMMLU2M2PW6ZCZFZJW2QQGJMEJ”,
    “type”: null,
    “size”: 47156,
    “referenceId”: “01NVQRYGSWLO2ZLARLYBBYFTTKOGLGMC2N”,
    “driveId”: “b!da_GQCGNTU-TpCq0a75y0fKw_skVS0xBqz7NHiYKvrzmRuCsFE47Q7RDO2bruoQi”,
    “status”: 1,
    “uploadSessionUrl”: null
    }
    ]

    Like

    1. Hi Thomas,

      I’ll happy to help but need more info. Expression code, error message and screen prints of each.

      NY

      Like

      1. Hi,
        I’m sorry I’m a bit new on this blog, but i can’t paste screen copies, or attach files.
        do you want me to send you details by email or is there a way to proceed via the blog ?
        thxs

        Like

  6. Hello Norm, I want add an attachment from “for a selected item” user input as an attachment to a list item in sharepoint. I suspect the concept is close to what you have demonstrated above but I am a bit stuck. Do you an example?

    Like

  7. Hi, tried your steps here, it works for me, the only thing im concern is just can multiple attachments compile in 1 row? Because on my end, when there is multiple attachments it creates multiple lines on the share point list.

    Like

    1. Hi Chona,

      I would review your steps and compare them with mine. My testing shows that attachments are added to a single list item.

      Let me know how you make out and thanks for reading!

      NY

      Like

  8. I have an MS form that is part of a team and my list is also part of the same team. Is there a way to just get the file path for each attachment and insert those into the List as hyperlinks instead of copying the document itself?

    Like

  9. I have an MS form that is part of a team. My list is also part of the same team. Is there a way to parse the file path of each of the uploaded documents and put the path into the list as a hyperlink instead of duplicating each of the documents?

    Like

    1. Hi docwisdom,

      It seems possible. You could use an expression to parse out the path and store the link. The Parse JSON action will have a “link” output that you can use to store the URL to the files. I would probably try a mix of the FIRST, LAST and SPLIT functions to achieve this.

      Let me know if you need help.

      Thanks for reading!

      NY

      Like

  10. Norm, I am grateful for this walkthrough. I have a question on this though. Is there an option to have the Compose/Parse JSON be conditional? The flow I have set up works perfectly when there are attachments in the MS form. The MS form I have set up allows attachments to be optional and this flow errors out when there are no attachments available.

    The error message in the Parse JSON is “Unable to process template language expressions in action ‘Parse_JSON’ inputs at line ‘0’ and column ‘0’: ‘Required property ‘content’ expects a value but got null. Path ”.’.”.

    Thank you for any feedback provided.

    Like

    1. Hi Soon,

      You can edit the JSON to allow NULL values. For example:

      “name”: {
      “type”: “string”
      },

      Can be updated to:

      “name”: {
      “type”: [“string”, “null”]
      },

      Thanks for reading!

      NY

      Like

      1. HI… i have the same issue and wish to make attachment optional. I tried your suggestion but am still getting the same error message.

        {
        “type”: “array”,
        “items”: {
        “type”: “object”,
        “properties”: {
        “name”: {
        “type”: [“string”,”null”]
        },
        “link”: {
        “type”: [“string”,”null”]
        },
        “id”: {
        “type”: [“string”,”null”]
        },
        “type”: {},
        “size”: {
        “type”: [“integer”,”null”]
        },
        “referenceId”: {
        “type”: [“string”,”null”]
        },
        “driveId”: {
        “type”: [“string”,”null”]
        },
        “status”: {
        “type”: [“integer”,”null”]
        },
        “uploadSessionUrl”: {}
        },
        “required”: [
        “name”,
        “link”,
        “id”,
        “type”,
        “size”,
        “referenceId”,
        “driveId”,
        “status”,
        “uploadSessionUrl”
        ]
        }
        }

        anything i did wrong

        Like

      2. It was the same error posted on Soon’s post. I managed to get round the problem with a conditional branch before the checking the attachment. If attachment is there, do the json if the attachment field is blank, do nothing.

        Like

      3. Hello MIndy,

        Try adding a Condition action that checks for length of the Get User ID action. If 0 then the ID does not exist.

        Hope that helps and thanks for reading!

        NY

        Like

      4. Norm, thank you for the response. I edited the JSON to allow for NULL values but am still receiving the following error: Unable to process template language expressions in action ‘Parse_JSON’ inputs at line ‘0’ and column ‘0’: ‘Required property ‘content’ expects a value but got null. Path ”.’.

        I have also edited the JSON to match what Mindy is doing below and am still receiving the same error message.

        Like

      5. Hi Soon,

        You may want to consider Mindy’s approach and add a Condition action that checks for a NULL attachments.

        Let me know how you make out.

        NY

        Like

    1. Hi Josh,

      It is complicated and I hope that you were able to implement the Flow for this use case. You are not the only one to voice your concerns on this point and I believe that Microsoft is listening. Hope this will be simplified in the future.

      Thanks for reading!

      NY

      Like

  11. Hi Norm,
    I basically followed the logic and steps, and it works. The only problem I have is that when I run the automation, there are 2 files created in my SP list – one with no attachment, another with an attachment. I wonder what should I do for it? Any recommendations will be appreciated!

    Look forward to your reply

    Like

    1. Hi Jessica,

      “there are 2 files created in my SP list – one with no attachment, another with an attachment”

      Are you saying that 2 list entries are created? If so is the Create item in a Apply to each loop?

      Thanks for reading!

      NY

      Like

  12. Hi Norm, this has been very useful but I have a small problem. For the last step I can’t seem to add the onedrive file content – it’s not even an option for me. Do you have any suggestions for troubleshooting?

    Like

    1. Hi Jamie,

      Sorry the late response. Hopefully you got past this issue. If not, make sure that you are getting output from the “Get file content using path” action. If it is null, then check if the path exists.

      Thanks for reading!

      NY

      Like

  13. Hi Norm,

    I’, trying to do something similar but less complicated. i want to attach files in my sharepoint library to the correct row in my client list. for example: a file from a client which was uploaded through onedrive and moved sharepoijt folder is to be added to the client’s row in my sharepoint list by referencing if the file name contains “first name”. “first name” is a column in my sharepoint list, containing the first names of my clients. so far i use the get items action with filter expression: contains(body(‘Get_items’)?[‘value’], ‘First Name’). but i get an error Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The ‘inputs’ property of template action ‘Get_items’ at line ‘1’ and column ‘2221’ is not valid. The action cannot reference itself.’.’.
    was wondering if you can help me out.

    Like

    1. Hi Rustie,

      Sounds like something is wrong with the Get items action. I’m not certain “contains” is supported with an OData filter query and would need to test to know for sure. I’m happy to help but need a few days to find some time.

      Thanks for reading!

      NY

      Like

  14. I have this working perfectly, having an MS Group form, where the submitter uploads a document and then submits the form. PowerAutomate then creates the SharePoint list item and attaches the Form’s attachment to the list item. My list has permissions for restricted contribute, so I do not want folks to navigate to the SharePoint site’s Documents>Apps>Microsoft Forms>etc., to be able to see the attachment that may have been uploaded by someone else. Is there a way in the PowerAutomate to delete the attachments from Documents>Apps>Microsoft Forms>… once they have been attached to the SharePoint list?

    Like

    1. Hi Annette,

      Interesting question. You should be able to use the SharePoint delete a file action.

      Thanks for reading!
      NY

      Like

  15. This works great for getting form responses with file attachments, but it fails every time someone submits a form without an attachment. How do I get both into my list?

    Like

    1. Hi Kat,

      Thanks for flagging this issue. Adding a check condition against Associated files – i.e. length greater than 0 – and then moving the add attachments to the “If yes” branch will fix this issue.

      I’ll update the blog shortly.

      Thanks for reading!

      NY

      Like

  16. Hi,

    Thx for this flow. But doens’t work with 2 pdf’s.
    Only 1 is uploaded, 2nd only name is coorect but file behind is same as the first. How can I solve this?

    Like

    1. Hi Caroline,

      Are you using the Body from the Compose Associated files output in your Apply to each that adds the attachments?

      I recently updated this blog post. Please review and confirm outputs in any loops.

      Thanks for reading!

      NY

      Like

Leave a 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 )

Facebook photo

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

Connecting to %s