Skip to content

Iterators

In the previous article, we placed the Get Values component to our automation and got the tweet contents and their dates. Now, we will move to the second step of the automation: checking the tweets scheduled for the current day.

How can we find the tweets for the current day? There are several ways to approach this. When solving problems in your automations, it’s helpful to step back from Monkedo and think about how you would tackle the task manually. In this case, we have a table with dates and tweet content. A simple approach would be to go through each row and check if the date matches today’s date. To do this in Monkedo, we can use the Iterate Table component, which lets us process each row one by one.

Iterating through table rows or list items is a common task in automations, especially when dealing with repetitive actions across a set of data. Monkedo provides two iterator components for this purpose: Iterate Table and Iterate List. You can find these components under the Flow Control category in the component panel, as shown below.

Iterators
Iterator components under Flow Control category

Both components take a collection of data as input and return each row or item individually to the automation flow. This allows you to handle each row separately, and any components connected to the iterator will perform the same actions for every row. This is how you create loops and repetitive actions in Monkedo.

In our automation, the Get Values component outputs data in a table format. You can see the input and output types next to their names in the component panel, as shown below.

table type

Since the output is a table, we will use the Iterate Table component to process each row. If the data type were a list, you would use the Iterate List component instead. Below are the details of the Iterate Table component.

Iterate Table Component
Iterate Table Component

This component takes 1 input and provides 3 outputs. The input takes the table we want to iterate. The outputs are Row, Number, and Done.

  • Row: Provides each row of the table individually. You can connect this output to other components to perform operations on each row's data.

  • Number: Outputs the row number, where the first row is 1, the second is 2, and so on. This can be useful if you need to reference the row number in your automation.

  • Done: Signals when all rows have been iterated. While the Row and Number outputs are active during the iteration, the Done output remains inactive until all rows are processed. You can use this output to trigger other operations once the iteration is complete.

To start, click on the Flow Control category in the component panel and select the Iterate Table component. Place it next to the Get Values component. Then, connect the output of Get Values to the input of Iterate Table. Your automation should now look like this:

Automation with Iterate Table component

In the previous article, we connected the Get Values component to the Schedule Trigger to establish the direction of the automation flow. Similarly, this new connection to the Iterate Table component tells Monkedo that after Get Values runs, Iterate Table should execute. Additionally, it passes the data output from Get Values to the input of Iterate Table.

Connections between components serve two key functions:

  1. Set the direction of the flow: They determine the order in which components execute.

  2. Send data from one component to another: They ensure that output from one component becomes input for the next.

Now that the input of the Iterate Table component is set to receive data from Get Values, the Run button on Iterate Table will turn blue, indicating it's ready to execute. You can click the button to run it.

If you see an error message like the one below, it means that the previous component (Get Values) was not run, so there’s no data for Iterate Table to process. To resolve this, simply run the Get Values component first, then run Iterate Table again.

no-input-error

Once the Iterate Table component successfully runs, the results will be displayed in the info panel. Let’s take a closer look at the outputs. Here, you can see that all 3 outputs of the component are listed.

The first output, Row, shows the data in the current row. The second output, Number, shows the number of the current row. On the outher hand, the third output, Done, is grayed out and there is an info text that says "Not activated yet." This is because, this output activates only when all rows are iterated and iteration is completed. Any component connected to this output will not work until the table iteration finished.

row-1

At this point, let’s run the Iterate Table component again to retrieve the next row. The outputs will now display data for the second row.

row-2

When designing an automation, you can run components multiple times to test different inputs or outputs. Monkedo saves all run results and allows you to switch between them, helping you test the automation with various scenarios. Each result is given a name which is visible at the top of the Results section. You can click this and select another result. Output values will be updated accordingly.

component results
Result of component runs are listed here with their name and the time they are created.

If you click the run button on the Iterate Table component enough times, you will eventually reach the end of the iteration and the Done output will activate as shown below. In this case, only the Done output is active and other inputs are inactive.

iteration complete

What is Next?

We’ve now set up iteration in our automation and learned key fundamentals of Monkedo. Iterators are crucial components you'll likely use in many future automations. In the next article, we’ll explore how to check the dates in the table rows to find the tweets scheduled for today.

See you in the next article !