> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.itential.com/itential-cloud/studio/workflows/child-job-looping/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server. # Use child job looping in workflows > Best practices for replacing forEach tasks with child job looping in Itential Platform workflow design for improved modularity and readability. Itential has reverted the deprecation of the **forEach** task, allowing it to remain in the platform. As a best practice, Itential recommends using a `child job` loop. In workflow design, there are scenarios where a `childJobLoop` is preferable to a **forEach** task. Using `childJobLoop` improves workflow readability and promotes modularity by centralizing looping logic rather than duplicating it across multiple workflows. It also provides a cleaner way to run sequential and parallel loops through a **child job** task. | Task | Description | Recommendation | | --------- | --------------------------------------------------------------------- | -------------------------------------------------- | | `forEach` | Executes a loop inside a job by iterating over each item in an array. | Replace with child job using a Loop Type property. | ## Convert a forEach task to a child job loop The main components of the conversion are: * Moving the looped task into its own child workflow. * Replacing the **forEach** task with a **child job** task that iterates over the array. * Mapping the input and output variables of the child job. #### Create a child workflow Create a new workflow containing only the tasks that were being looped in the **forEach** task. Cloning the original workflow and removing non-looping tasks is often the easiest approach. #### Replace the forEach task In the original workflow, remove the **forEach** task and replace it with a **child job** task. Set the **Workflow** field to the child workflow created in the previous step. #### Set the loop type Set `loopType` to `sequential` or `parallel`. #### Set the loop array Set `loopArray` to the referenced `dataArray`. Ensure that the items in the array are objects. ## Pass inputs directly to a child job (basic example) ### Parent workflow In the starting workflow, the **forEach** task iterates over an array `[1,2,3]`. For each iteration, the task makes a REST call to an API endpoint. ![](/_fern-img/b03797679a6a816b44bbcbdc097d29f6eb09f82bcf43e7589e890fae4b6f27b6.webp) ### Create the child workflow Create a child workflow for the task being looped. Clone the original workflow and leave only the looping tasks. ![](/_fern-img/dcfc8abe7322f68f35bef7273ec8fb7dd9bc826da540760b1cff5f15035a3e43.webp) ### Replace forEach with child job In the parent workflow, remove the **forEach** task and replace it with **childJob**. ![](/_fern-img/f65ceaa98edb79d94d2c3d2bc2bdaf8ad210cd7c385e9e0840466254ee2562da.webp) ### Set the loop type Open the task details for the **child job** task. Update the **Workflow**, **Loop Type**, and **Loop Array** fields. Use `Sequential` for **Loop Type**. Click **Save**. ![](/_fern-img/57c016b9336e69bf169c3a18e062f288961cd2622311d582fa75a74016adb6be.webp) ### Convert array to objects The values passed to the **child job** task must be objects. Open the **New Job Variable** in the parent workflow and change the `data_array` input to `[{},{},{}]`. Click **Save**. ![](/_fern-img/47ea8f67fd17c3bbaf80d37fc2f6f80236a70b95f5cc5b9d9bba58e63c8bfc01.webp) ### Run the workflow Click **Run** to execute the workflow and confirm the conversion is complete. --- ## Use transformations to pass inputs to a child job (advanced example) This example builds on the basic example above and demonstrates using a JST to map loop array values to child job inputs. ### Restore the parent workflow Open the **New Job Variable** and change `data_array` back to `"[1,2,3]"`. Click **Save** to restore the original state. ### Create a JST Open the task details for the **child job** task. Click the **+** icon next to the **Transformation** field to create a JST that maps the **Loop Array** to input values for the child workflow. ![](/_fern-img/5e5c6ced61763aeeea875dc83e38bdd10ada14d22115d522b907d0047667e03f.webp) ### Set the outgoing schema On the JST page, set the outgoing schema with an `id` of `num` and a type of `integer`. This allows the `data_array` variable to be passed to the outgoing schema using the original `[1,2,3]` input array. Save and close the JST. ![](/_fern-img/b883e09f9bef83718ddca9704700ab03ea633a45108a9e2818e0906bb7151f40.webp) ### Configure the viewData task input Open the task details for the **viewData** task. For the `message` variable, change **Reference task** to `job` and **Reference variable** to `message`. Click **Save**. ![](/_fern-img/ebcf64571d3bdb33bda5f9f5677c1106a091171d59a3b421f33e57a40a1d68d6.webp) Use the JST to pass `$id` of `message` instead of `num`. This creates the object array `[{"message":1},{"message":2},{"message":3}]` that is passed to the **child job** task. ![](/_fern-img/adcf4cb2d823a39e7e7538142fc6f1cca8a8756b16c0b50fa430ca0abacef4da.webp) Save the transformation, return to the parent workflow, and click **Run**. After completing each child job, the **Rest Call Output** is visible. ![](/_fern-img/0fcb043b9c7b2af768bfd53559b39f8f4b026e0263dc77f6f2969d2241803314.webp) ### Capture child job task output If the parent workflow requires the output of the **child job** task, use the output data from job\_details. Add a **viewData** task and configure it to receive job\_details as input. ![](/_fern-img/cec44baf31bf13e1ba6c269dfb5a2529b88a405cd2d0ba2f86edadaf84bacbbe.webp) Pass the job\_details output to the `body` variable. ![](/_fern-img/899557f65e13bed589944c4417c344806568f0098883705a123de090dd47e36a.webp) Run the parent workflow and work through each child job's **viewData** task. The job\_details of the **child job** task appear as output per iteration. ![](/_fern-img/4b36f8b9d2a49de4714cef8c9c3a0dc34f0371c38855015c4033a3ffc9b23eae.webp) Note that no job variables may be visible initially. To get the REST API call output, open the child job in designer mode, select the **RestCall** task, and check the **Job Variables** box under **Outgoing**. ![](/_fern-img/c5ab48e9dba8895cd61c2465d7401091d5a468474d82dbe711f75f901cb78bb0.webp) After running the parent workflow again, the job\_details output for each child job iteration includes the REST call results. ![](/_fern-img/8980b402c874ecd31eebd94a4f963a947eec6a07ff546cb90883bb68a648481d.webp) ## Related resources * [Itential video: how to loop child jobs inItential Platform workflows](https://www.youtube.com/watch?v=DSVDNjwnL2o) > Best practices for replacing forEach tasks with child job looping in Itential Platform workflow design for improved modularity and readability.