Articles in this section
Category / Section

Iterator Storage

4 mins read
Updated:

The Iterator Storage module in FlowMattic allows users to store and manage data from each iteration within the Iterator loop. This data can be stored in two formats: Array (JSON) or String. However, it’s important to note that the user needs to explicitly set the array parameters or define the string format in the Iterator Storage configuration. Only the data defined in these parameters will be stored and accumulated as the loop processes each item.

Iterator Storage works in two storage formats:

  1. Store as Array (JSON format)

  2. Store as String (String format)

Below is a detailed explanation of both storage formats, along with examples to illustrate how they function.


1. Store as Array (JSON Format)

Functionality:

When “Store as Array” is selected, you need to define the data parameters (fields) that you want to store from each iteration of the loop. These parameters will form the array items, and new data from each loop iteration will be appended to the previously stored array within the same workflow execution.

The data is not automatically stored—you must explicitly map each field to be stored.

Example:

Let’s say you’re working with an e-commerce workflow where you’re processing a JSON array of products that contain the product name and price:

{
  "products": [
    {
      "name": "Addidas",
      "price": 4000
    },
    {
      "name": "Nike",
      "price": 3500
    }
  ]
}

Workflow Steps:

  1. Iterator Module: The JSON array (products) is passed into the Iterator module, and the loop processes each product individually.

  2. Iterator Storage Configuration: In the Iterator Storage module, choose Store as Array. Then, set the data parameters for the array:

  • Parameter 1: Name (e.g., {iterator.name})

  • Parameter 2: Price (e.g., {iterator.price})

  • Click on Add More to add any additional parameters if needed.

  1. Save and Test: Click on Save & Test Action to see how the first product (Addidas) is stored in the array.

  2. Live Execution: When the workflow runs in live mode, each product is added to the array as a separate element, resulting in the following output:

[
  {
    "name": "Addidas",
    "price": 4000
  },
  {
    "name": "Nike",
    "price": 3500
  }
]

Key Points:

  • Defining Array Parameters: The array won’t automatically store each item; you must define the fields (parameters) that should be included in the array.

  • The array will continue to append data from each iteration within the same workflow session and is reset when a new session begins.


2. Store as String

Functionality:

When “Store as String” is selected, you also need to define the string format by specifying which data fields from the loop iterations should be concatenated. Each new string data is appended to the previously stored string, creating a cumulative output across all iterations in the loop.

Again, the string format is not automatically storedyou must define the string structure for it to work.

Example:

You want to process the same list of products, but this time, you wish to store the name and quantity of each product as a concatenated string.

Input data:

{
  "products": [
    {
      "name": "Addidas",
      "quantity": 2
    },
    {
      "name": "Nike",
      "quantity": 5
    }
  ]
}

Workflow Steps:

  1. Iterator Module: The Iterator processes each product in the array.

  2. Iterator Storage Configuration: In the Iterator Storage module, select Store as String. Then, define the format of the string:

  • String format: {iterator.name} x {iterator.quantity} (for example, “Addidas x 2”)
  1. Save and Test: When testing, the first string will be:
   Addidas x 2
  1. Live Execution: During live execution, the second product (Nike) will be processed and appended to the stored string, resulting in:
   Addidas x 2
   Nike x 5

Key Points:

  • Defining String Format: Similar to the array, the string is not automatically created. You must specify the format for how each iteration’s data is stored.

  • The string is appended with each iteration and resets with each new workflow execution.


Conclusion

The Iterator Storage module is a flexible tool for storing data as either a JSON array or a concatenated string during workflow execution. By setting the parameters or defining the string format, you can control precisely what data is stored and how it is accumulated during iterations. This ensures that only the required data is processed and used in subsequent workflow steps.

If you need further clarification or examples for a specific use case, feel free to ask!

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