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