Alternative to "For Each" Activity in Flow Designer

mrreddy534
Tera Contributor

Hi Experts,I 've been struggling with this issue for the past two weeks and haven't found a proper solution yet.

 

Is there an alternative to the "For Each" activity in Flow Designer?

 

I have a Lookup Records action that retrieves multiple records, and I need to apply a Custom Action to each record individually. Currently, using For Each, but looking for a different approach to achieve the same functionality without using For Each.

 

Is there any alternative way to apply the custom action to each record?

18 REPLIES 18

GopikaP
Mega Sage

Hi @mrreddy534 , what steps do you plan to execute in this workflow? Can you share an example?

Hi @GopikaP the flow having around 130 steps, at one point I want to create like below.

 

1. Using a For Each loop, I iterate over the Multi-Row Variable Set (MRVS) and creating new records.


2. After creating the records, I use a Custom Action to copy all variables from the main submitted RITM to the newly created RITMs.


3. Using a Lookup Activity, I retrieve all RITM records associated with the request.


4. I want to create a Custom Action where the input will be the records retrieved from the Lookup Activity. In this custom action, I need to trigger a traditional workflow for all the retrieved Request Item (RITM) records. Is it possible to create such a custom action to trigger workflows in Flow Designer? If so, what would be the best approach?


5. I know how to trigger a workflow and how to create a Custom Action to trigger it using a For Each activity. But in this case, I want to avoid using For Each activity and try a different approach.

The reason I am avoiding the For Each loop is that after calling the traditional workflow, every RITM under that corresponding request has a Catalog Variable (e.g. "Command") that needs to be updated. The expected behavior is:

First RITM’s Command should get the first row's Multi-Row Variable Set (MRVS) data.

Second RITM’s Command should get the second row's MRVS data, and so on.


The issue with using the For Each loop is that the workflow gets stuck in a loop, causing the last row’s data to overwrite all RITMs. As a result, all RITMs receive the same Command value instead of their respective row data.

To avoid this issue, I am searching for a way to achieve this using a Custom Action, where I can directly pass the lookup records and trigger the workflow for all of them at once. This is why I am looking for a solution to achieve this through a Custom Action rather than a For Each loop.

mrreddy534
Tera Contributor

Hello @GopikaP @Murtaza Saify 

 

Until the third step, I have completed the development, but I am currently stuck at the fourth step. I need to figure out how to trigger the workflow for all the lookup records without using a For Each loop. If anyone has any ideas or suggestions on how to achieve this, please guide me.

Hi @mrreddy534 ,

Whenever we trigger a workflow from the Flow Designer or via a script, the 'current' object must be passed in that call. It's not possible to pass multiple records to the workflow at once.

However, I understand that you want to trigger the workflow for multiple records simultaneously to prevent the flow from getting stuck or entering a loop.

In the Flow Designer, after the 'Look Up Records' step, select 'For Each.' Within that, choose 'Call a Workflow' under flow logic and select the desired workflow. Make sure to uncheck the 'Wait' condition so that the workflows run simultaneously.

Like this - WFSC.png

@GopikaP If I'm not mistaken, 'Call a Workflow' does not work for flows running on the sc_req_item table