# For Loop

## **Introduction**

The "For" condition in DBSync Cloud Workflow allows users to create customized workflows by iterating over collections of data. This enables dynamic processing based on specific criteria, making it possible to perform various operations like insert, upsert, or update from a source to a target.

## **Prerequisites**

Before you begin, ensure you have:

* A configured project in DBSync Cloud Workflow.
* The necessary connectors (for example, Salesforce and QuickBooks) set up.

## **Use Case**

In this use case, we iterate through opportunity products to trigger item creation.

{% stepper %}
{% step %}

### Configure the Flow

* In the Flow screen, drag the **Flow** Action from the Actions palette on the left and drop to the center of the screen.
* Click **Configure** on the flow panel to configure the flow.
* In the Flow configuration panel that opens on the right side, enter the required description for the flow and click **Save**.
  {% endstep %}

{% step %}

### Add and configure a Query action

* Drag and drop a **Query** action into the flow and **Configure**.
* Define the Source as Salesforce and select your source connector. Select the Opportunity Object. \
  **Note:** Ensure that you add the Related OpportunityLineItem.
* Click **Save**.&#x20;

  <figure><img src="https://1036205596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv9avy716UiAsS24zOznZ%2Fuploads%2FlITsrF05rMldbutm8BsW%2Funknown.png?alt=media&#x26;token=a72eabd7-6966-4187-a52f-b6eca2ade569" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

### Add the For condition and iterate

* Drag and drop the **For** condition into the flow.
* Configure the **For** condition to iterate over the products associated with the queried Opportunity. In the right panel, from the **Records in** dropdown, select *OpportunityLineItems/Records*. This allows you to process each product individually.

<figure><img src="https://1036205596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv9avy716UiAsS24zOznZ%2Fuploads%2FBAccGdCuW48lv1gooj2C%2Funknown.png?alt=media&#x26;token=15b0b4ed-2cb2-49bf-b02f-d428988a2bb2" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Transform, Write and Debug

* Add a **Transform and Write** action to insert the items into QuickBooks using the relevant opportunity product data.
* Add a **Debug** action to print the results of the operation. This will display a debug card with the details of the products associated with the Opportunity.
  {% endstep %}

{% step %}

### Run the workflow

* Click Run <img src="https://1036205596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv9avy716UiAsS24zOznZ%2Fuploads%2FsY0I8zt7VlHpmkDCaXxA%2Funknown.png?alt=media&#x26;token=8d8607dd-ad57-4dad-a070-e5c8d23169da" alt="" data-size="line"> to execute the workflow.
* Monitor the console output to verify that the For loop is iterating correctly and that the appropriate actions are taken.

The Related Items will be created in QuickBooks.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
PRO TIP&#x20;

When using the "For" condition, ensure that your data set is well-defined and that the items being iterated over are relevant to the operation you intend to perform. This will help avoid unnecessary iterations and improve workflow efficiency.
{% endhint %}

**Related Content**

* [Implementing Conditional Logic with "If Conditions"](https://docs.mydbsync.com/cloud-workflow/if-conditions): Learn how to apply conditional logic within your workflows to dynamically control the execution of tasks and flows.
* [Creating and Managing Queries](https://docs.mydbsync.com/cloud-workflow/ipaas/functional-concepts/query): Discover how to build and manage queries for retrieving and validating data across your integrations.
* [Debugging Flows](https://docs.google.com/document/d/14MCRfISd6NI_tM7yAUu_ci-mz_Y8PzE_Zffq8f4tjDI/edit#heading=h.q8inv0iuih8v): Explore techniques for troubleshooting and debugging your workflows to ensure they run smoothly and efficiently.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mydbsync.com/cloud-workflow/2026_create-your-workflow/action/conditions/for-loop.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
