cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
elizabethharms
Regular Visitor

Trying to build a flow that puts attachments into a specific folder based on a list column entry

Hi all!

 

I'm trying to build a flow that will allow employees to upload photos to specific SharePoint document libraries based on how they answer a question in a Microsoft Form.

 

The form has:

  • Which event are your photos from (as a choice question)
  • Attachments

 

My current flow:

  • When a new form response is submitted ...
  • It copies the attachments to my OneDrive ...
  • Creates an item in a SharePoint list ...
  • Copies attachments to the SharePoint list.

 

I can't figure out how to then route it to a particular document library based on the answer to the first question (either in the form or in the list). In other words, if someone chooses 2022 Staff Retreat from the choices, I want the attachments to flow to the document library called 2022 Staff Retreat.

 

I'm starting to wonder if this is even possible.

2 ACCEPTED SOLUTIONS

Accepted Solutions

So there isn't going to be a direct action to Copy a file since you are trying to go from OneDrive to SharePoint. You will need to use the SharePoint - Create file action. This is not much different than the SharePoint - Add attachment action.

 

I can't make a duplicate of your flow without seeing the expanded steps, but it probably isn't necessary. You have done the hard part already. To finally create a file in the SharePoint document library, it is going to work much like how you are adding the attachments to SharePoint.

 

Switch Create FileSwitch Create File

 

In my quick example the Switch is using the Choice response from the Form and then it will create a file in the identified folder.

Yours will probably be slightly different, so instead of a Create File action within each of the Switch Case, you will probably have an Apply to Each within each Case. And within that Apply to Each you will have the Create File action.

I'm guessing you could use the same "Add attachment to SharePoint list" step within each Switch case, but replace it with the action Create file.

You could put the Switch inside of an Apply to Each, but I think it looks cleaner to have it outside and then the individual Apply to Each for each case.

 

This requires that the document folders are already made and the form choice response matches each case. This also doesn't allow for a single form response to send photos to different folders; that would get more complex.

 

Do you think you can make it work like this?

(If you get stuck, let me know, but also add a screenshot of your steps opened up fully so I can copy what you have. Then I'll make a complete example.)

View solution in original post

Thank you, very helpful!

 

I think you are going to have to reformat your flow. Right now you have these separate Apply to Each and they aren't going to work together, if they do then it is because of luck or only a single file.

 

For example

  • The Apply to Each - "Get file content from Onedrive" is going through the body of the action "Generate array from multiple attachments" and getting file content for each one.
  • Then the next Apply to Each - "Add attachment to SharePoint list" is going through the body of the action "Generate array from multiple attachments" and adding an attachment to a SharePoint item, but it is using the Body of the content that comes from the previous Apply to Each.

The Problem:

  1. Apply to Each is like its own container and each loop is for single item. So how is one container of item loops supposed to pair with another container of item loops? It can't.

You basically only need 1 Apply to Each action that is going through your array of attachments and performing actions for each item. So immediately after the "Get file content using path" put the action "Add Attachment" so that it is still on the same name and same file content.

-----------------------------------------------------------------------------------------------------------------------

 

I made a full example and have tested it to work. The attachments are able to be seen in the sharepoint list item when clicked on, and the files in the folder can be seen without corruption.

I probably should have just done this from the start, but I have never done anything with forms attachments so I kind of thought you already had it all set up correctly since you said it was working. Either way, at least I learned how to do it too!

 

Below are the steps of the flow, if you make yours look similar to mine then it should work.

 

Note: I added "Get File Metadata" because I wanted to make sure I was using the dynamic content for the file name.

I am also using the "id" of the file to get the metadata and content. This is basically the same as "Get File Content By Path" except I like using the "id" because it is more precise. You can swap them if you prefer.

 

This is an overview of the steps in the full flow:

Flow OverviewFlow Overview

 

The first steps of the flow are pretty obvious and you already had them in place. I basically copied yours.

Flow Steps Detail 1Flow Steps Detail 1

 

This is going to be the only "Apply to Each" in the flow since it is acting on the individual items coming from the ParseJSON step.

Flow Steps Detail 2Flow Steps Detail 2

 

This is the Switch control that is within the Apply to Each. Each create file action is using the Name from the Get File Metadata and then using the Content from Get File Content.

Flow Steps Detail 3Flow Steps Detail 3

 

 

So this should make it easier to put together, let me know if you have any issues. If this works for you, then mark it as the solution so other people can see it easier.

 

Good Luck!

View solution in original post

13 REPLIES 13

It is very possible! You can put a Switch control in your flow and have it use the form response. Then for each switch case, just have the response options.

 

https://www.youtube.com/watch?v=6KokllQUX2I 

That is a youtube video that shows a Switch control.

 

If your form question is - Select which event these photos are from:

  • 2022 Fun Time
  • 2022 Christmas
  • 2023 New Years

Switch ControlSwitch Control

 

Let me know if this works for you,

elizabethharms
Regular Visitor

I have high hopes for this @wskinnermctc ! Here's what my flow looks like right now (and so far it works). I'm guessing I'd need to put it after the last item, right? Once I put in the switch, do you know what action I use to copy the files to a document library? I appreciate all of your help! I'm a first-timer.  🙂

 

elizabethharms_1-1687902435120.png

 

So there isn't going to be a direct action to Copy a file since you are trying to go from OneDrive to SharePoint. You will need to use the SharePoint - Create file action. This is not much different than the SharePoint - Add attachment action.

 

I can't make a duplicate of your flow without seeing the expanded steps, but it probably isn't necessary. You have done the hard part already. To finally create a file in the SharePoint document library, it is going to work much like how you are adding the attachments to SharePoint.

 

Switch Create FileSwitch Create File

 

In my quick example the Switch is using the Choice response from the Form and then it will create a file in the identified folder.

Yours will probably be slightly different, so instead of a Create File action within each of the Switch Case, you will probably have an Apply to Each within each Case. And within that Apply to Each you will have the Create File action.

I'm guessing you could use the same "Add attachment to SharePoint list" step within each Switch case, but replace it with the action Create file.

You could put the Switch inside of an Apply to Each, but I think it looks cleaner to have it outside and then the individual Apply to Each for each case.

 

This requires that the document folders are already made and the form choice response matches each case. This also doesn't allow for a single form response to send photos to different folders; that would get more complex.

 

Do you think you can make it work like this?

(If you get stuck, let me know, but also add a screenshot of your steps opened up fully so I can copy what you have. Then I'll make a complete example.)

elizabethharms
Regular Visitor

It works! 

 

Thank you so much for your help. I've been struggling with this all day. 

Well, I've found a new problem. The flow works and everything goes to the right document libraries. However, the files appear to be corrupted and won't open. It appears to be a problem with it going from OneDrive to the SharePoint List. Any ideas how to fix that? I can only find information about emails with corrupt attachments.

Are the file names correct? More specifically, using the correct name with extension such as .docx or .pdf or .xlsx

 

I have made the mistake of just using the file names and it doesn't work without the correct extension.

elizabethharms
Regular Visitor

Yes, they are. It's putting my name at the end, but the extension is correct.

elizabethharms_0-1687981577095.png

 

So the files that are put into the list item as an attachment work correctly? You can open them up and they are not corrupted? 

 

It is only the files that are being put into the SharePoint document library that are corrupted?

elizabethharms
Regular Visitor

No. I thought they were fine because I could see the file name, but I don't think I had tried to open one previously. Now, when I try to open it from the SharePoint list, it doesn't open.

Can you show a screenshot of your steps? Not just the steps and names (like in a previous photo of yours), but the steps expanded so I can see the values that are being used.

elizabethharms
Regular Visitor

Sure! 

Part one

elizabethharms_0-1687984227852.png

Part two (the array came from a successful original test)

elizabethharms_1-1687984274147.png

Part three

elizabethharms_2-1687984355285.png

Part 4 (only showing one option, but they're all the same)

elizabethharms_3-1687984495274.png

 

 

Thank you, very helpful!

 

I think you are going to have to reformat your flow. Right now you have these separate Apply to Each and they aren't going to work together, if they do then it is because of luck or only a single file.

 

For example

  • The Apply to Each - "Get file content from Onedrive" is going through the body of the action "Generate array from multiple attachments" and getting file content for each one.
  • Then the next Apply to Each - "Add attachment to SharePoint list" is going through the body of the action "Generate array from multiple attachments" and adding an attachment to a SharePoint item, but it is using the Body of the content that comes from the previous Apply to Each.

The Problem:

  1. Apply to Each is like its own container and each loop is for single item. So how is one container of item loops supposed to pair with another container of item loops? It can't.

You basically only need 1 Apply to Each action that is going through your array of attachments and performing actions for each item. So immediately after the "Get file content using path" put the action "Add Attachment" so that it is still on the same name and same file content.

-----------------------------------------------------------------------------------------------------------------------

 

I made a full example and have tested it to work. The attachments are able to be seen in the sharepoint list item when clicked on, and the files in the folder can be seen without corruption.

I probably should have just done this from the start, but I have never done anything with forms attachments so I kind of thought you already had it all set up correctly since you said it was working. Either way, at least I learned how to do it too!

 

Below are the steps of the flow, if you make yours look similar to mine then it should work.

 

Note: I added "Get File Metadata" because I wanted to make sure I was using the dynamic content for the file name.

I am also using the "id" of the file to get the metadata and content. This is basically the same as "Get File Content By Path" except I like using the "id" because it is more precise. You can swap them if you prefer.

 

This is an overview of the steps in the full flow:

Flow OverviewFlow Overview

 

The first steps of the flow are pretty obvious and you already had them in place. I basically copied yours.

Flow Steps Detail 1Flow Steps Detail 1

 

This is going to be the only "Apply to Each" in the flow since it is acting on the individual items coming from the ParseJSON step.

Flow Steps Detail 2Flow Steps Detail 2

 

This is the Switch control that is within the Apply to Each. Each create file action is using the Name from the Get File Metadata and then using the Content from Get File Content.

Flow Steps Detail 3Flow Steps Detail 3

 

 

So this should make it easier to put together, let me know if you have any issues. If this works for you, then mark it as the solution so other people can see it easier.

 

Good Luck!

elizabethharms
Regular Visitor

Thank you so much again! I've now tested it, not just with the flow (which looked like it was working) but also opening the files at each point. I really appreciate your help!

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,037)