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.

Ekran Resmi 2024-10-22 15.44.14

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 "When" 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 (meaning we will type an example value manually) to test the condition component. Click the Select button and you will see the different types of values you can provide as shown below. You may think that you need to select the Date type in the list but if you look at the image above, type of the "When" column is shown as "Text" (next to column name, in parentheses). This is because Google Sheets provides all data in Text format. This is also the case for some other apps. Some values, especially dates, can be provided in Text format. But don't worry. Monkedo always shows the type of the received data in the editor so you can know what you are working with. These will be explained in the next article in detail. For now, we need to choose the same type as the left side of the rule. Therefore, we need to select the Text option.

Condition value input selector

An input box will appear. You can write the date of the current 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

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. What you type is not important. Write a random value.

condition wrong value

Save it and run the Condition component again. This time the Otherwise output will activate while the Today output stays inactive.

condition not met

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!