Skip to content

Conditions

In the previous articles, we set up our automation to retrieve tweet content from Google Sheets and iterate through each row using the Iterate Table component. Now, we need to check if the date on each row matches the current date. For this, we’ll introduce the Condition component.

The Condition component allows us to define rules that control the flow of our automation based on certain conditions. In this article, we’ll explore how to use this powerful tool to check for specific conditions in our data. Condition component is listed under Flow Control category as shown below.

condition-in-selector

The Condition component works by evaluating input data against a set of rules. It takes two primary inputs as shown below:

  1. Input: The value we want to check. In our case, this will be the date from the current row of the table.

  2. Conditions: A list of query rules that are evaluated against the input. When a rule matches, the corresponding output is triggered.

condition component

Condition component's outputs are created as you add conditions. For each condition you add, a new output port is placed on the component block. You need to add at least 1 condition but you can add even more. This way, you can check different conditions on the input data and for each condition case, you can allow your automation to perform something different. This is how you shape the flow of automations based on a condition in Monkedo.

Open the component selector by clicking the Flow Control category and select the Condition component. Place it next to the Iterate Table component. Connect the Row output of Iterate Table to the Input input of the Condition component. Your automation should look like this:

automation with condition

As conditions are evaluated against input data, we need to provide data to the Input input of the Condition component to create conditions. If you didn't connect a component to this input or it doesn't have data you will get a warning as shown below when creating conditions.

no input for condition warning

The connection to the input of the Condition component may not have data if:

  1. You didn't run the previous component. Hence it has no output data.

  2. You ran the previous component but the output didn't activate.

Remember that in the previous article, we checked the case where all rows are iterated and Done output of the Iterate Table is activated. In this case, Row output of Iterate Table is not active. Therefore, if that result is selected, the connection we created between this output and the Condition component will not have data. Simply, make sure that another result is selected in the info panel of Iterate Table as shown below.

row 1 selected
Result named "Row 1" is selected among many others

Now, click the Condition component. In the info panel, you will see an option to "Set Query Rules" as shown below.

set query rules

Click that to open the Query Form. This is where you create the condition. It needs a short name and a set of rules. Let's set the name of the query as "Today". Then, click the input box to add the first rule. You will see the columns of the row as shown below.

input expression for query

A rule is a comparison between two values. A condition requires at least one rule but the query form is powerful and allows you to create more complex conditions with many rules depending on your use case. In our automation, we will just check if the date of the row is same as current date. So, a single rule is enough.

  1. In the menu show above, select the Date column of the row.

  2. After that, select the Equal (=) operator.

  3. Finally, we need to set the right side of the rule which will be the current date.

Before getting the current date, lets set a constant value to the right side of the rule to test the condition component. Click the Select button and select Text. An input box will appear. You can write the date of the row provided to the Condition component. We want to see what happens when the condition is met. So make sure that you entered the correct value. In this tutorial, the date of the selected row is "9/27/2024". Therefore this value is entered into the form. If the date value is different in your automation, set it accordingly. The final form of the rule should look like this:

query form with constant value

After clicking the Save button you will notice that the condition is listed in the info panel with the name "Today" we set in the query form. In addition to that, an output port is created for this condition as shown below. If you add more conditions, a new output port will be created for each of them.

today option

Now, click the run button on the Condition component to see its result. You will notice that since the condition is met, that output is activated and the input provided to the Condition component is forwarded to this output. The other output named Oherwise activates only when none of the conditions are met.

condition met
Condition named "Today" is met and corresponding output is activated.

Now open the Query Form again by clicking the Today condition in the info panel. You may need to click the Configuration tab in the info panel to see it as shown below.

configuration tab

After opening the query form, change the right side of the rule so that when we run the component again the condition won't be met. Save it and run the Condition component again. This time the Otherwise output will activate while the Today output stays inactive.

condition not met
No condition is met and Otherwise output is activated.

Performing actions conditionally is a common scenario in automations. In this case, you can create conditions as many as you need and then connect different components to each output. Automaton flow continues from the components connected to the active output and components connected to inactive outputs won't run. This way you can conditionally execute actions in your automations.

What is Next?

We explored how to use the Condition component to check conditions and run components conditionally. However, we used a fixed date for comparison, which isn’t ideal. For our automation to work properly, we need to use the current date each time it runs.

In the next article, we’ll learn how to dynamically retrieve the current date and use it in our condition.

See you in the next article!