ForEach: Invoke new workflow within loop


#1

Is it possible within a ForEach loop to invoke a workflow? Goal is to reduce the size of the current workflow but I must stay inside the ForEach loop as I am iterating through multiple rows in Excel.

Read row
Perform multiple\complicated activities (log into secure website, extract\store data etc.)
Read next row

Thank you,

Thom


#2

Hi,
Sure, you can do that. What you will need to do is in the workflow you are calling is create In and Out arguments so the data from Excel can be sent to it and information from the workflow can be sent back to later output somewhere.

You can also abandon the For Each and use a Flowchart arrangement where you create a counter Int variable to set the row number, then use the arrows to make your loop. It’s a little more visually organized.

Either way works though.


#3

It is recommended.


#4

Thank you. I like the flowchart arrangement but I’m not able to locate an example on how to accomplish this without the use of a For Each Row activity. Can anyone share an example of using the flowchart counter methodology when reading Excel rows?


Add to collection Breaks For Each
#5

Here is a workflow I created just for you! lol. It shows how you can store the dataRow from the dataTable and implement it in a loop.

Hope that helps. Thanks.
flowexample.xaml (15.3 KB)

EDIT: Edited example with fixes.


#6

Awesome and thanks.

Attached is your example with my Excel data and variable mods. It doesn’t appear it is iterating to the next row?

Would you mind take a brief look to see why?

flowexample2.xaml (17.7 KB)
QTS_Company_List.xlsx (10.6 KB)


#7

You might need to set the default value for n to 0 and default value of boolEnd to False.
Oh also, change the scope of n to Main so it’s global. It’s probably resetting each time since it’s not global.


#8

Thank you. In addition to your recommendations I add to move the Increment RowNumber after the Assign Row to capture the first row but its now working as expected. Much appreciated.


#9

No problem. And, actually you want to set the Default value to -1 and leave the Increment Row above the Assign. The reason is because it will add 1 after so if you need to use that number it will be wrong. It will probably work though if you don’t use it later on in your script.

Thanks.


#10

Make sense. Thanks.


#11

Hi @Badita,

I try to invoke a workflow file inside a for each activity, using an email message as parameter.
Can you explain me why this happens?

I would expect that mail is of MailMessage type, but apparently not.

Kind regards,
Dimitrios


#12

Hi,

@Medical_1234 Yes it’s is possible…always split into new workflow so it’s easy to maintain the code and reusable also.using in and out argument you can pass the value and get the value from out argument.

Regards,
Arivu


#13

@dntakoulas check the parameters for your “For each”. The TypeArgument should be set to System.Net.Mail.MailMessage which will make “mail” the correct type if it isn’t already.


#14

Hey ClaytonM,

Thanks for the help, that was set to Object by default and I did not think to take a look, as I was sure it would be set to System.Net.Mail.MailMessage when I created the for each activity.

Problem solved :slight_smile:

Br,
Dimitrios