Articles in this section
Category / Section

Iterator Module

5 mins read
Updated:

Detailed Guide to FlowMattic Iterator Module

The FlowMattic Iterator Module is a core feature that helps users loop through a given JSON array, process each individual item in the array, and map the data with subsequent steps in a workflow. This is particularly useful when handling multiple similar data items, like a list of orders, product details, or any repeated data within a JSON structure.

Below is a detailed guide explaining what the FlowMattic Iterator is, how it works, and when you should use it, followed by a real-world example.


What is the FlowMattic Iterator?

The FlowMattic Iterator is a module designed to handle JSON arrays in a workflow. It allows you to:

  • Loop through each item in a JSON array.

  • Extract individual items one by one.

  • Use the data of the extracted item to map it to subsequent steps in the workflow.

The Iterator works in two parts:

  1. Iterator (Start): The module where looping through the JSON array begins. This is where the first item from the array is processed in test mode.

  2. Iterator End: The module that marks the end of the iteration loop. All steps between the Iterator and Iterator End will be repeated for each item in the array.


How Does the FlowMattic Iterator Work?

Step-by-Step Process:

  1. Add the Iterator to Your Workflow
  • In your workflow, drag and drop the Iterator module where you need to process a JSON array. This should be placed after the trigger step (e.g., receiving JSON data from an API or webhook).
  1. Input the JSON Array
  • In the Iterator configuration, map the JSON array you want to loop through. This could be an array of objects received from the previous workflow step, such as a list of orders, contacts, or products.
  1. Save and Test Action
  • After mapping the JSON array, click on the Save and Test Action button.

  • When testing, FlowMattic will return the first item of the array as a response. This allows you to map the fields of the first item with the rest of the workflow steps. For example, if you are looping through a list of orders, you can map details like order ID, customer name, and order total.

  1. Add Steps After the Iterator
  • Now, add any additional steps that should be repeated for each item in the JSON array. These could include actions like sending an email, updating a database, or triggering another service.

  • The values from the first item in the JSON array will be used in these steps during testing.

  1. Add the Iterator End Module
  • To mark the end of the loop, add the Iterator End module after the steps you want to iterate. This tells FlowMattic when to stop repeating the steps for each item in the array.
  1. Execution in Live Mode
  • When the workflow is executed in live mode, FlowMattic will loop through the entire JSON array. Each item will be processed individually, and the steps between the Iterator and Iterator End will be repeated for each one.

  • The entire workflow continues beyond the Iterator End once the looping completes.


Example Use Case: Processing a List of Orders

Scenario:

You receive a webhook with a JSON array containing a list of customer orders. The JSON data looks like this:

{
  "orders": [
    {
      "order_id": "1001",
      "customer_name": "John Doe",
      "total": "$150"
    },
    {
      "order_id": "1002",
      "customer_name": "Jane Smith",
      "total": "$200"
    }
  ]
}

Workflow Steps:

  1. Webhook Trigger: Receive the JSON array containing the list of orders via a webhook.

  2. Iterator Module: Place the Iterator after the webhook trigger and map the orders array to the Iterator module.

  3. Save and Test: FlowMattic will display the first order (John Doe) during testing. You can map fields like order_id, customer_name, and total to further actions.

  4. Action Step 1: Add an action to send an email confirming the order. Map the data fields from the first item (John Doe) into the email content.

  5. Iterator End: Add the Iterator End module after the email action to mark the end of the loop.

  6. Live Execution: Once live, FlowMattic will loop through the array and process each order individually. First, it will handle John Doe’s order, and then repeat the same steps for Jane Smith’s order.


When to Use the FlowMattic Iterator?

The Iterator is useful in situations where you need to process multiple similar data items, such as:

  • Handling bulk orders received from an e-commerce system.

  • Processing a list of subscribers in an email marketing tool.

  • Looping through a collection of products or inventory items.

  • Iterating through a set of API responses with repeated data, such as a list of tasks, users, or transactions.

By using the Iterator, you eliminate the need to manually process each item in the array and automate repetitive tasks efficiently.


Key Takeaways:

  • The Iterator is crucial for looping through and processing JSON arrays.

  • Save and Test Action only processes the first item, allowing you to map fields to subsequent steps.

  • In live execution, the Iterator automatically loops through all items in the JSON array, performing each step for every item between the Iterator and Iterator End.

  • Ideal for processing lists, bulk data, or any repeated elements within a JSON structure.

The Iterator simplifies your workflows by automating the processing of multiple items without manually handling each one, improving efficiency and scalability.

If you need further clarification or a specific example, feel free to ask!

Iterator Storage and Iterator End are two additional modules that can be used in conjunction with the Iterator module in the FlowMattic application. These modules are different in nature and have different functions.

Iterator Storage: The Iterator Storage module is used to store the values from the Iterator in an array or string to use it outside the Iterator action step. When using the Iterator module, it may be necessary to save the values generated by the Iterator and use them later in the workflow. This is where the Iterator Storage module comes into play. This module allows users to store the values generated by the Iterator in an array or string, which can be accessed and used later in the workflow. This provides greater flexibility and functionality to the workflow, allowing users to perform more complex actions.

Iterator End: The Iterator End module is used to stop the Iterator process where this action step is inserted and only let the Iterator loop through the action steps between the Iterator and Iterator End modules. When using the Iterator module, it is necessary to define the end of the loop. This is where the Iterator End module comes into play. This module is used to indicate the end of the loop and ensure that the Iterator only loops through the action steps between the Iterator and Iterator End modules. This ensures that the workflow runs smoothly and efficiently, and prevents any errors or issues that may arise from an infinite loop.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Access denied
Access denied