menu

How to loop through all items of a table and perform an action


To loop through all items of a table and perform an action, follow these steps using the example of a table called Products with an empty field called SKU, which we will be filling with a value created by combining the word NEW with the ID of the particular item:

  1. Open the Products table, click on Options, and then select Automations and New Flow.

  2. Add a flow name, such as Create SKU.

  3. Select a trigger. We will use: Manually by Flow or Button.

  4. Leave the IF section blank.

  5. In the THEN section, do the following:

  6. Drag a Search Loop block from the Logic section of the left sidebar. This block lets you go through every item in the table conditionally.

    1. In this case, we want to iterate through all products where the SKU field is empty.

    2. To achieve this, we can set the condition to Where SKU contains [empty value].

    3. We need to select our Products table from the Table option.

    4. The SKU field should be selected from the Where option.

    5. The condition should be set to Contains.

    6. The Value field can be left empty since we do not need to search for a specific value.

  7. Create a variable for the SKU value by dragging a Calculate Variable block from the "Logic" section of the left sidebar.

    1. Give the variable a name, such as sku, and write a formula for creating the SKU.

    2. Write a formula for creating the SKU using PHP syntax.

    3. The formula should concatenate the word NEW with the ID of the product that is currently active in the loop.

    4. Use the @ symbol to access the ID, which provides two options:

      1. Current - for the item in which the flow is triggered

      2. Products - for the item currently active in the loop.

    5. The formula should be "NEW"+@{Products: ID}.

  8. Drag an Update Record block from the Actions section of the left sidebar. This block lets you update an item.

    1. Select the Record as Current Products Record

      1. This Products Record is the item in which the flow is triggered

      2. Current Products Record is item currently active in the loop

    2. The SKU field as the field to update

    3. Input @{Variable: sku} to select the variable created earlier as the new value for the SKU field.

  9. It is always a good practice to perform calculations as a variable and use the variable in the action field instead of performing calculations directly in the action field.

  10. Save the flow.

  11. Click Edit and then Simulate Variables to test the flow without executing changes on the items. This is a helpful step to ensure that the flow works correctly before making any changes to the actual items.

  12. Finally, click Run and enter any item ID to execute the flow and fill the SKU field with the newly created values.

InfoLobby © 2024 Globi Web Solutions