Skip to main content

Lesson 12 · Automations: Mairu keeps watch for you

M
Written by Mairu

Path

Duration

Level

Before you start

🟣 Configurator · Level 2

45 min

Advanced

[[10 · Consultas - reutilizar los datos que ya tienes

Queries - reusing the data you already have]] · [[11 · Programaciones - el trabajo planificado

Schedules - planned work]]

Events react when someone saves. But there are situations that do not depend on anyone saving anything: controls that have gone days without review, documents about to expire, too many rejections in one morning. That is what automations are for: Mairu reviews the data every so often and acts if it finds something.

🎯 By the end you'll know how to

  • Tell when to use an event and when an automation.

  • Create an Indicator-type automation with a condition and a threshold.

  • Create a List-type automation that acts on several records.

  • Use the current date to make an automation dynamic.


🧠 The idea: query + frequency + action

An automation is a query that Mairu runs periodically:

EVERY     day at 8:00
QUERY     controls pending review
IF        there are results (or the value exceeds a threshold)
DO        notify / send email / change status / webhook / schedule form

Event

Automation

Fires

On saving a response

With a frequency (every X minutes, every day, every Friday…)

Looks at

One response

All of those a query returns

Typical question

"When someone saves this, does anything happen?"

"Is there anything in my data that needs attention?"

Two types

Type

Uses a query…

Example

Actions

Indicator

of type Indicator (a number) and a condition on it

If there are more than 2 NOT OK today…

Notify, send email, webhook

List

of type List: acts on each record it returns

For each control pending review…

Plus: change status and schedule form


🛠️ Guided practice

Automation 1 · Alert if rejections pile up (Indicator)

The query. In Settings > Queries create the query NOT OK since a date, type Indicator, with a parameter of type Date called desde:

{
  "select": "temperatura",
  "aggregate": "count",
  "from": "control_envasado",
  "where": [
    {
      "allConditions": {
        "conditions": [
          { "field": "resultado", "operation": "=", "value": "NOT OK" },
          { "field": "created_at", "operation": ">=", "value": "desde" }
        ],
        "type": "and"
      },
      "type": "and"
    }
  ]
}

With count the responses that meet the conditions are counted; since temperatura is required, they all have it. Test it with Testing before continuing.

The automation.

  1. In Settings > Automations create a folder Quality and, inside it, an automation Accumulated rejections.

  2. When > Query: type Indicator, query NOT OK since a date. Assign the current date to the desde parameter.

  3. Condition: greater than 2.

  4. Frequency: every 60 minutes.

  5. Action: Send email to calidad.prueba with the subject More than 2 NOT OK controls today.

Automation 2 · Reminder of unreviewed controls (List)

The query. Create Controls pending review, type List, filtering by the status name:

{
  "select": ["created_at", "linea", "lote", "motivo_rechazo"],
  "from": "control_envasado",
  "where": [
    {
      "allConditions": {
        "conditions": [
          { "field": "state_id", "attribute": "name", "operation": "=", "value": "Pending review" }
        ],
        "type": "and"
      },
      "type": "and"
    }
  ]
}

The automation.

  1. Create Review reminder, type List, with this query.

  2. Frequency: every day at 8:00.

  3. Action: Notify the Quality department.

💡 With the Schedule form action you could go a step further: create a review task for each pending control, with the data inherited from the query. If you enable Create automatic response, Mairu directly creates the response with that data.


🔍 Check that it works

  • Record three NOT OK controls today: in less than an hour the Accumulated rejections email arrives.

  • Leave a control in Pending review until the next day: at 8:00 Quality receives the notification.

  • Change that control to Non-compliant with the status selector: the next day it no longer appears in the reminder.


⚠️ Common mistakes

  • "I can't create the automation." If you don't have any, create a folder first.

  • Using an automation where an event is enough. If the alert must go out at the moment of saving, use an event: it is immediate and simpler.

  • Frequencies too high with noisy actions. An Indicator automation that is met every 5 minutes will send an email every 5 minutes. Adjust frequency and threshold with the person who receives the alerts in mind.

  • Queries with fixed dates. A query with "2026-11-01" written by hand will stop working tomorrow. Use a Date-type parameter and the current date.

  • Scheduling forms en masse without reviewing their events. Responses created automatically also fire the events of the target form.


🏋️ Challenge

Quality wants to monitor the expiry dates: every Monday, a list of the packaged batches whose expiry falls within the next 30 days, sent by email. Design the query, think about which parameter you need and create the automation. Hint: review the case Controlling training and certificates that expire, it solves a very similar problem.


📚 Learn more

Did this answer your question?