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

Hi @GopikaP, yes, it looks almost similar. Once I check the flow, I’ll have a bit more clarity on this. Could you please share the flow

Hi @mrreddy534 , please find the attached update set.

 

If you find my replies useful, you can mark them as helpful.

Your help is truly invaluable, @GopikaP. I really appreciate your time and effort in guiding me through this. Sorry for troubling you again.

 

I am a little confused (it might be my mistake in understanding) about your provided solution, which is why I am writing once again. Please check it once.

I will explain the exact requirement one more time:

1. I created a "number of rows" variable. For example, if the MRVS contains three rows, this variable will populate as "one, two"; if the MRVS contains five rows, it will populate as "one, two, three, four"—always one less than the total rows. This is because we need to create one less record so that the newly created records + the already submitted record from the portal equal the total MRVS rows. I then converted the "number of rows" variable into an array to allow iteration, where each iteration creates a new record.


2. After record creation, I copy all the RITM variables and values from the parent RITM to the newly created RITMs.


3. After that, I use the "Lookup Records" action to fetch all RITMs under the same request. Then, I use a "For Each" loop, providing the output of the "Lookup Records" action as input. Inside this loop, I add a Custom Action to trigger the traditional workflow.


4. Details of the workflow:

 

• Automation is happening inside this called workflow, which is why we need to trigger another catalog workflow from this catalog flow.

• The workflow creates a Catalog Task (not in Flow Designer).

• Inside the "Catalog Task" activity script, we insert values into the "Command" variable.

The automation is happening on this variable.

 


For example, based on your suggestion, the "Command" variable should be populated using:
Child Company + User + Role (concatenated values).

Thus, each RITM’s "Command" variable should be filled with different details:

1st RITM "Command" = 1st row MRVS data (Child Company + User + Role)

2nd RITM "Command" = 2nd row MRVS data (same format)

… up to 5 RITMs


However, your provided example performs all activities within Flow Designer itself, so I suspect it may interfere with automation. - this is my genuine doubt.

 

Process Flow Summary:

1. Convert MRVS (1 less count) into an array


2. Create new records


3. Copy variable data from parent RITM to new RITMs


4. Lookup all RITMs under the request


5. Use "For Each" loop to trigger the workflow for each record (this workflow creates a task and fills the "Command" variable)


6. After this, my remaining flow in Flow Designer will execute

 

This is the overall structure.

 

Your help is greatly appreciated!

mrreddy534
Tera Contributor

Hi @GopikaP

 

If you're still looking at this, I wanted to share one more key observation.

 

In the calling workflow in catalog task activity, I commented out all the existing scripts and only added a simple update script to modify the Command variable for each RITM. The goal was to update the Command with the current RITM number.

 

To ensure proper execution, I also added a 60-second time delay in Flow Designer before triggering the workflow. Here's what I observed:

 

When the workflow triggers for the first RITM, the Command is updated correctly with its own RITM number.

 

However, the same number also gets updated in RITM 2 and RITM 3.

 

After 60 seconds, when the workflow triggers for RITM 2, the Command updates correctly for RITM 2, but now RITM 1 and RITM 3 also get the same number.

 

The same issue repeats for RITM 3, causing all RITMs to hold the latest updated number instead of their own unique values.


It seems like the latest update is overriding all the previous ones across all RITMs, which is the main issue I am facing. If I can get this working correctly, my problem will be resolved.

 

Just wanted to highlight this key observation in case you have any thoughts on it.

 

Your help is greatly appreciated!

 

This is the script which I am using in catalog task activity.

 

var ritmGr = new GlideRecord('sc_req_item');

ritmGr.addQuery('sys_id', current.sys_id);

ritmGr.query();

if (ritmGr.next()) {  

    gs.info("Updating RITM: " + ritmGr.number);

    

    ritmGr.variables.command = ritmGr.number;

    ritmGr.update();

}