cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jakson
Resolver I
Resolver I

If Tree to iterate Several Folders' Items

I'm struggling to word this meaningfully so if anything more needs to be said from me, please let me know.

 

I've created two Flows. One Flow puts all of the attachments from my emails into a folder. The same flow iterates over these items to determine which month folder to put them in determined by the text present in the name. The number of items put into any month folder is counted and turned into a variable. That count variable is passed to the second Flow.

 

The second Flow determines if there are any files in any of the month folders using an if statement tree, "If CountVar >= 1 Then"... This part is working flawlessly. When I have 11 items for October, 11 files are put into my October folder and 11 items are passed to this second Flow.

 

The issue is that the second Flow will always iterate only one folder's items. As though it can only "see" the one count variable.

 

My current Flow If / Else If statements are designed as such:If Tree Design.PNG

(FileCount - FileCount gets me to a solid starting point to count up again. I know I have a number items from my previous Flow, but I want to make certain that this second Flow is actually counting/iterating all of the items. Later in my For-Each loop I add +1 to the count variable to return back to the original count... assuming everything went without hitch.)

 

The first If statement is to check December. I figured this part was rather arbitrary, as to which end of the year I begin my evaluation from.

 

The Else Ifs flow from December to January and each evaluate the same thing. If the var passed from the first flow is 1 or greater, then check the contents of that folder and later grab those files for further processing.

 

As I was saying earlier, this process works flawlessly... once. I could have 60 items for October and 5 for November, and since November iterates first, only 5 November are processed. The purpose of passing this file count var is to prevent unnecessary checks and processing. If I know for a fact I only have files to do with October, there's no point in checking January through September, or November and December.

 

I've been working on this project in small pieces for about 2 weeks now. I'm starting to go cross-eyed trying to battle my way through new issues that keep cropping up due to oversight or poor design.

 

I need this Flow to accept whatever number variable it was passed and do an action for each corresponding folder instead of exclusively performing actions on whichever folder comes first numerically.

1 ACCEPTED SOLUTION

Accepted Solutions
MichaelAnnis
Super User
Super User

These all need to be separate if statements. ElseIF will not run if the first if statement is met.

 

Therefore, you need it to look like this. 

IF augnotenum >=1 Then

 ‘Do something

EndIF

IF julnotenum >=1 Then

 ‘Do something

EndiF

 

that way each one will be ignored if it is 0 and it will attempt to process all of them. 

View solution in original post

3 REPLIES 3
MichaelAnnis
Super User
Super User

These all need to be separate if statements. ElseIF will not run if the first if statement is met.

 

Therefore, you need it to look like this. 

IF augnotenum >=1 Then

 ‘Do something

EndIF

IF julnotenum >=1 Then

 ‘Do something

EndiF

 

that way each one will be ignored if it is 0 and it will attempt to process all of them. 

I see now. Thank you, MichaelAnnis!

 

I should've been thinking in my VBA headspace. I've had to do several nested if-trees where the "do this" action is predicated on one or two determinations.

 

Thank you again!

I gave this a swing and I couldn't get it to produce the desired behavior. I think this has to do with my use of the For-Each loop.

 

The condition to fire the For Each loop, and what to iterate over, are predicated on the results of any single If statement above it. Whatever If evaluates to true provides the For Each the target folder. That methodology right there is the issue.

 

To continue using the above method I mentioned I formatted my Ifs to be as you had, Michael.

 

If NovNoteNum >=1

Do something

End If

If OctNoteNum >=1

Do something

End If

 

Except, in addition to the reformatting I've also added an additional If statement after the For Each loop and a new boolean variable.

 

If NovNoteNum >=1

NovCounter = 1

Do something

Go To For-Each loop starter label

... Some code...

 

At the end of the For Each statements:

If NovCounter = 0

Go to NovNoteNum If statement label

 

This allows for the desired effect from the Ifs but not so directly. Now the whole process must complete before it can target a new folder with new items to iterate, but at least it works from end to end.

 

Thank you very much for your help, MichaelAnnis!!!

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Top Solution Authors
Top Kudoed Authors
Users online (3,152)