cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Charline74
Helper III
Helper III

Creating a file: if it exists do not create it / if it does not exist create it

Hello everyone

I would like to know how to get the answers to a form:
If the person has never filled in the form it creates a folder with their name on it
and if the person comes back and fills in the form again, the file is not created.

This is what I currently have as a flow :

 

Charline74_0-1627894972290.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
eric-cheng
Solution Sage
Solution Sage

Hi @Charline74 ,

 

Try the below flow and assume Q1 is the name of the respondent 

 

1) Initialize a boolean variable and set it to @false

ericcheng_0-1627911410419.png

 

2) Use a Get Files (properties only) action to get all files and folders from your document library.  Add an ODATA filter FileLeafRef eq 'Q1' (replace Q1 with your Forms field).  FileLeafRef is the internal name for name in SharePoint.

 

ericcheng_4-1627911750983.png

 

 

3) Loop through each returned file and add a condition for IsFolder = true.  If true, it means a folder was found with the name.  Set the boolean variable to @false

ericcheng_2-1627911565152.png

4) Exit the loop and add another condition to check your boolean variable.  If false, it means no folder was found and you can proceed to create a folder and add a file (same logic that you already have).

ericcheng_3-1627911625652.png

 

Run for first form submission which will  create a folder and file

ericcheng_7-1627912220826.png

 

Run for second submission with same name which will skip

ericcheng_8-1627912262441.png

 

 

 

--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up

Connect on LinkedIn

View solution in original post

7 REPLIES 7
eric-cheng
Solution Sage
Solution Sage

Hi @Charline74 ,

 

Can you clarify whether you are asking:

 

1) Why the file isn't created when the user submits the form the second time

2) How to make sure the file isn't created again when the user submits the form the second time

 

--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up

Connect on LinkedIn

Charline74
Helper III
Helper III

Hi @eric-cheng 

 

How to make sure the file isn't created again when the user submits the form the second time

eric-cheng
Solution Sage
Solution Sage

Hi @Charline74 ,

 

Try the below flow and assume Q1 is the name of the respondent 

 

1) Initialize a boolean variable and set it to @false

ericcheng_0-1627911410419.png

 

2) Use a Get Files (properties only) action to get all files and folders from your document library.  Add an ODATA filter FileLeafRef eq 'Q1' (replace Q1 with your Forms field).  FileLeafRef is the internal name for name in SharePoint.

 

ericcheng_4-1627911750983.png

 

 

3) Loop through each returned file and add a condition for IsFolder = true.  If true, it means a folder was found with the name.  Set the boolean variable to @false

ericcheng_2-1627911565152.png

4) Exit the loop and add another condition to check your boolean variable.  If false, it means no folder was found and you can proceed to create a folder and add a file (same logic that you already have).

ericcheng_3-1627911625652.png

 

Run for first form submission which will  create a folder and file

ericcheng_7-1627912220826.png

 

Run for second submission with same name which will skip

ericcheng_8-1627912262441.png

 

 

 

--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up

Connect on LinkedIn

View solution in original post

Charline74
Helper III
Helper III

@eric-cheng  

Thank you for your answer, just a question what do you mean by Forms field ? 

 

Is this the form id link ? 

Hi @Charline74 ,

 

The value/field with the folder name

 

--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up

Connect on LinkedIn

@eric-cheng 

Is this the name of the folder I want to create or the name of the folder where responses are sent? Do you have an example?

VSTrath
Regular Visitor

@eric-cheng This is very helpful but not quite working for me.

 

My scenario is slightly different. I want users to be able to submit a form and for these details to go into a list item on Sharepoint. This part is done. But in the form there is an option to upload documents. I want a flow that creates a folder for this list item, adds these documents to it and then adds a link to the folder location in the list item column called 'Folder'. This is so that the person assigned to respond to this task can click on the folder location easily, using the list essentially as a dashboard.

 

However, instead of triggering this flow when the form is submitted I am attempting to replicate this for when a new list item is added. This is because there will be occasions when we need to manually add a list item within Sharepoint rather than it come through the form submission. I still want the folder to be generated automatically to ensure consistency in folder naming but the actual files will need to be added manually to the folder in this case.

So this is what I'm thinking:

 

1. When an item is created

2. Get item

3. Create new folder

4. Create file

5. Create sharing link for a file or folder

6. Update list item

 

However, I don't know what to put into steps 4 - 6. Wondered if you could expand on the step you posted about below and maybe offer some other pointers? I haven't included the set variable etc steps because I don't think I need these but may be wrong. Many thanks.

 

VSTrath_0-1632407484295.png

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (3,018)