ForEach: Invoke new workflow within loop

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,



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.


It is recommended.

1 Like

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?

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.

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)

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.

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.

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.


Make sense. Thanks.

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,


@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.


@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.

1 Like

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:


Hello Sir, i used your example but i have many workflows (different workflows) to invoke each time a increase of row number. How can i do it ?

Helloo sir, how can i make a loop in my situation.

Read row
Invoke different workflow
Read next row
Invoke different workflow
Read next row
Invoke different workflow

Hi @jhuven_mina
You can use the “For Each” or “For Each Row” activity. If you use the regular For Each, just change the ArgumentType to DataRow and put datatablevariable.AsEnumerable.

If the workflow you want to invoke is the same for each row, then just do this:

For each
    Invoke Workflow File

If the workflow you want to invoke is different for each file, then use a Switch activity, so you can use a different Invoke based on the value of the row item.

To use the row variable within the For each, just do row("columnname").ToString, where row is the variable name used for the For each (which can be any word actually, so don’t be afraid to be more specific than just row or item).

I hope this answers your question. Also, explore the Academy which I think is linked on the top of the Forum’s home page; this will go over loops I believe.


1 Like

EDIT: use an Excel Scope and Read Range as read-only to initialize your datatable variable which you will be looping through each row, before the For each loop.

Hello @ClaytonM ,

I tried the Switch activity and now its Okay. Thank you so much sir!

1 Like