{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":4182,"path":"build-workflows/workflow-studio/flow-logic-for-each.md","title":"For Each flow logic","bundle":null,"doc_type":null,"release":"australia","body":"\n# For Each flow logic\n\nApply one or more actions to each record in a list of records.\n\nThe **For Each** flow logic applies one or more actions to a list of records. The flow applies the actions contained within the flow logic to each record in the list.\n\n**Note:** When you set a data pill value from inside a For each item branch of flow logic, the data pill value is only available to other actions in the same branch. Referencing a data pill value that was set inside a For each branch from outside of the flow logic branch produces a null value.\n\nIterating over a large number of records can be resource intensive, especially when the For Each logic block includes complex actions for each iteration. To avoid performance issues, turn off reporting using the **com.snc.process\\_flow.reporting.level** system property. For more information, see [Workflow Studio flow system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/flow-designer-system-properties.md).\n\n## Inputs\n\n-   **Items**\n\n    Data type: **Records**\n\n    List of Sys ID values or Records data pill specifying the records to process in sequence. You can use a Look Up Records action to generate a list of records. For more information, see [Look Up Records action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/lookup-records-flow-designer.md).\n\n    **Note:** If you want to process items in a particular order, you must first sort the items in this input in advance. For example, use the Order by option to sort the results of a Look Up Records action.\n\n\n## Outputs\n\n-   **\\[Table name\\] Record**\n\n    Data type: **Record**\n\n    Current record in the loop.\n\n    **Note:** By default, all flow loops only store execution details for the first and last iterations of a loop. To report on all iterations of a loop, create a flow execution setting record for each flow that you want to collect loop execution details. For more information about flow execution settings, see [Flow execution settings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/flow-execution-settings.md).\n\n\n## Send an email for each configuration item potentially affected by a change\n\n\\[Omitted image \"example-for-each-flow-logic.png\"\\] Alt text: Configuration of the For Each flow logic using a list of Configuration Item records\n\nThis example flow starts when a change request record is created. The flow uses a Look Up Records action to find Configuration Item records assigned to the requester of the change request. The flow uses For Each flow logic to send an email about each configuration that might be affected by the change request. The output of the Look Up Records action contains the list of records to process.\n\n\\[Omitted image \"example-for-each-flow-logic-execution-details.png\"\\] Alt text: Flow execution details of the For Each flow logic\n\nThe flow execution details show the configuration item record used for each iteration of the loop.\n\n## General guidelines\n\nUse these general guidelines with a For Each flow logic.\n\n-   **Avoid adding more than 1000 items**\n\n    Avoid iterating over lists with more than 1000 records. Keep your list of records smaller to optimize flow performance. To iterate over lists with more than 1000 records, divide the list into smaller sections and use multiple flows.\n\n-   **Avoid defining stages that depend on a For Each flow logic**\n\n    Flow Designer prevents you from adding stages within a **For Each** block. You can only add stages before or after a **For Each** block.\n\n-   **Avoid nested For Each loops**\n\n    Avoid nested For Each loops that process many records. Nested loops may cause the flow to run until it is stopped by the flow transaction quota rule, which prevents flows from running longer than an hour. For more information about transaction quotas, see [Transaction quotas](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/c_TransactionQuotas.md).\n\n\n**Parent Topic:**[Workflow Studio flow logic](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/flow-logic.md)\n\n**Related topics**  \n\n\n[Append to Flow Variables flow logic]()\n\n[Assign subflow outputs flow logic]()\n\n[Call a workflow flow logic]()\n\n[Do the following until flow logic]()\n\n[Do the following in parallel flow logic]()\n\n[Dynamic flows flow logic]()\n\n[End Flow flow logic]()\n\n[Exit Loop flow logic]()\n\n[Get Flow Outputs flow logic]()\n\n[Go back to flow logic]()\n\n[If flow logic]()\n\n[Make a decision flow logic]()\n\n[Set Flow Variables flow logic]()\n\n[Skip Iteration flow logic]()\n\n[Try flow logic]()\n\n[Wait for a duration flow logic]()\n\n"}}