cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ScottJM
Level: Powered On

Excluding Folders From "When a file is created" Using Sharepoint

Hello,

 

I am trying to create a flow that when a file is added it creates a main folder with 3 folders inside then moves the original document. So far i have managed to get the flow to get the file name of the file added then create a folder with the file name and then a file within it. Unfortuatley because the "When an item is created or modified" trigger it creates an infinte loop as whenever a file is added in the library do this. Is there a way to stop this or exclude folders from the trigger?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
v-lin-msft
Level 10

Re: Excluding Folders From "When a file is created" Using Sharepoint

Hi @ScottJM,

 

You could use Send an Http request to SharePoint action to create your folder and the subfolder.

It can avoid trigger your flow multi times and you can not to delete these files:Annotation 2019-06-17 163900.png

 

Method: POST

Uri:

_api/Web/GetFolderByServerRelativeUrl('/sites/SiteName/LibraryName')/Folders

Headers: 

    Content-Type   application/json; odata=verbose

 

Accept   application/json; odata=verbose

Body:

{ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/sites/SiteName/LibraryName/New Folder/SubFolder1'}"}

 

Besides, about your question Is there a way to stop this or exclude folders from the trigger?

Yes, you can add a condition that judges the file whether is a folder under the trigger:

-If yes, do the next steps;

-If no, end the run.

Annotation 2019-06-17 172038.png

Best Regards,

Community Support Team _ Lin Tu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

10 REPLIES 10
Super User
Super User

Re: Excluding Folders From "When a file is created" Using Sharepoint

You can't filter on that trigger.

 

The way I normally get around this is to have a Run Flow yes/no field on the list/library. The default is YES and then the first action the Flow performs is to set that fella to No. Then it goes on and processes it as you wish.

 

The action of setting it to No will also trigger the Flow to run, but you have a condition in your Flow to ONLY CONTINUE IF RUN FLOW IS SET TO YES.

 

This way you can **bleep** that infinite loop in the bud.

 

- Mark

svijay_001
Level: Powered On

Re: Excluding Folders From "When a file is created" Using Sharepoint

You could use a condition and filter out the files/folder based isFolder property.

 

You can branch out perform action only files when IsFolder Property is set to false. 

 

001.png

Super User
Super User

Re: Excluding Folders From "When a file is created" Using Sharepoint

If you could provide an expanded screenshot of your Flow and steps, and of any detailed error messages you're receiving we could likely better assist you.

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

ScottJM
Level: Powered On

Re: Excluding Folders From "When a file is created" Using Sharepoint

So this is what i currently have. I am using the .txt files to create new folders for me then removing them but everytime a new one is created as you can probably tell it restarts the flow and creates an infinite loop

Capture3.PNGCapture4.PNGCapture5.PNG

v-lin-msft
Level 10

Re: Excluding Folders From "When a file is created" Using Sharepoint

Hi @ScottJM,

 

You could use Send an Http request to SharePoint action to create your folder and the subfolder.

It can avoid trigger your flow multi times and you can not to delete these files:Annotation 2019-06-17 163900.png

 

Method: POST

Uri:

_api/Web/GetFolderByServerRelativeUrl('/sites/SiteName/LibraryName')/Folders

Headers: 

    Content-Type   application/json; odata=verbose

 

Accept   application/json; odata=verbose

Body:

{ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/sites/SiteName/LibraryName/New Folder/SubFolder1'}"}

 

Besides, about your question Is there a way to stop this or exclude folders from the trigger?

Yes, you can add a condition that judges the file whether is a folder under the trigger:

-If yes, do the next steps;

-If no, end the run.

Annotation 2019-06-17 172038.png

Best Regards,

Community Support Team _ Lin Tu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

ScottJM
Level: Powered On

Re: Excluding Folders From "When a file is created" Using Sharepoint

 

 

Hi @v-lin-msft,

 

Do you know if it possible to create the folders using the Integrated dynamics as the name? as every file that comes in needs to have a folder created with the name of the file then 4 folders created inside of it. also if im using the "When a file is created" wouldn't the flow start everytime a new folder is created? Or do i add the "Check if folder" before trying to create the new ones?

 

Edit: Tried using the flow shown above however i am getting the following error.

Capture6.PNG

v-lin-msft
Level 10

Re: Excluding Folders From "When a file is created" Using Sharepoint

Hi @ScottJM,

If you create folders using this method, you can dynamically define the folder name, as shown by the red line in the image. Similarly, you can define the names of subfolders in the same way.

Annotation 2019-06-18 093305.png

 

Since the method you used to create folder before need to create a new file, if you use the "When a file is created", it will trigger the flow every time. Realistically, the structure of your stream will trigger multiple times even if you add a condition to determine whether it is a folder or not.

 

As the problem that you met shown as your screenshot, you could share your flow configuration to us.

 

Best Regards,

Community Support Team _ Lin Tu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ScottJM
Level: Powered On

Re: Excluding Folders From "When a file is created" Using Sharepoint

This is the Flow that is currently giving me the error i cannot figure out why and it's starting to get really frustrating.

Capture7.PNG

v-lin-msft
Level 10

Re: Excluding Folders From "When a file is created" Using Sharepoint

Hi @ScottJM,

 

Could you show a screenshot of the error message, please?

Highlighted
ScottJM
Level: Powered On

Re: Excluding Folders From "When a file is created" Using Sharepoint

All sorted now accidently copied an extra ' and } which killed the whole thing haha, typical coding. Everything is working as expected now thanks for all the help!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (6,901)