Loops within Loop

Trying to develop a solution wherein for each loop takes files (PDF) from given location, adds another PDF file from a different folder,then from an excel file it takes password and encrypts and saves the PDF.
So the loop goes goes like this For Each>For Each>For Each(for each row in excel).
It is successfully completing the first loop,but for the second loop its taking the first file and first row only.Its not increment in second & third loop.
Please help!!

@pereira_mark

Inside second loop use IF Condition if Both PDF matches then do you logic for second loop.
Same for the third loop.

Revert back if any help.

Thanks,
Suresh J

Main.xaml (64.6 KB)
@sureshj
Thanks for the help.
Can you please look at the attached code and guide me the steps i have missed.

1 Like

@pereira_mark I’m trying to figure out what you’re trying to do in the workflow still.

So you want to get all PDF files, then go through them one by one. For each of these PDF files, you want to add ALL “backup” pdf files (so every single PDF receives ALL of the “backup” pdfs), then you want to grab a password from excel.

Is the password from excel different for each PDF? Also, are you meaning to only add ONE “backup” pdf for each of the PDF files?

@Dave
Yes, you got it rights, the passwords in the excel are different for all the PDF’s and the PDF from “backup folder” to be inserted in each of the PDF files.

@pereira_mark In that case you should use 2 For Each statements (not 3). For each 1stPDF file, then For each BackupPDF file. The excel file you only want 1 password. So you could use a for each row in excel combined with an if statement at the beginning, but it’s probably a better idea to just get the specific password you want instead of iterating through the whole thing each time.

Also, the inner-most loop will be executed many, many, many times. Because each time the 2nd loop runs, the 3rd loop runs. This means if you have 5 files in the inner-most loop and 10 files in the 2nd loop, it will run through those 5 files 10 times which I don’t think you want.

Instead it should be something like the below pseudo code:

For each MainPDF
   For each row in Excel
      If password in excel matches the one I want for this PDF
         Then assign password
                  break for each loop
         Else do nothing (leave blank)
      End if
   Next row in excel
   For each BackupPDF
       Add backup to MainPDF
   Next BackupPDF
   Add password to MainPDF
   Save MainPDF
Next MainPDF

@Dave, tried your logic, but still am unable to put the logic of inserting PDF file from BACKUP folder in a loop. Bot’s still picking up the first file from BACKUP folder.

Can you please share with me an xaml file

Thanks

Could you upload the file where you tried the logic I had written out above?