# Build your first automation

> Step by step from an empty editor to a tested automation. When a critical security incident is created, it notifies the information security officer, creates a task on a board and sends a mail to the management.

This guide builds a complete automation for Brandt & Söhne. Whenever someone records a security incident with the severity <Ui>Kritisch</Ui> (critical), three things should happen within seconds:

1. Tom Keller, the information security officer, gets a notification in the bell and by e-mail, with a link to the incident.
2. A task "Assess incident" appears on the general board, assigned to Tom, with high priority.
3. The management gets a mail to `management@example.com`.

Along the way you use every part of the editor: a trigger, a condition, three kinds of step, placeholders and the test run. The same steps work for any other source; only the fields differ.

## Before you start

- You need the permission `automation.manage`. Administrators have it. Without it, build the same thing as one of your own automations under <MenuPath to="My profile > Automations" />; it can then notify only you and cannot send mail.
- The source in this example is <Ui>Sicherheitsvorfälle</Ui> (security incidents) from the information security area. Any source you may read works the same way.
- The cron job `AUTOMATION_EVENTS` must be switched on, or the automation will not react to new records. If it is off, the editor tells you so. See [Run automations for the tenant](/automations/administration/#switch-on-the-cron-jobs).

:::note[Labels from the server are in German]
Names of sources, their fields and values, and the names of actions come from the server and are in German for now, also in the English interface. This page quotes them as they appear, with the meaning in brackets the first time.
:::

## Set up the trigger

<Steps>

1. Open <MenuPath to="Settings > Operations > Automations" /> and click <Ui>New automation</Ui>.

2. Under <Ui>Name</Ui>, enter `Critical security incident`. Under <Ui>Description</Ui>, write what it is for, so that the other administrators know: `Tells the ISO right away and creates a task on the general board.`

3. Leave <Ui>Runs as</Ui> empty. The automation then runs as you, with your rights. If someone else is responsible for incidents, pick that person instead. The automation can then only do what that person could do.

4. In the card <Ui>When</Ui>, pick the trigger <Ui>A record is created</Ui>.

   <Screenshot src={shot_new_trigger} alt="The card When with the four triggers and an empty data source" caption="A new automation starts with the trigger. The data source comes next." />

5. Under <Ui>Data source</Ui>, pick <Ui>Sicherheitsvorfälle</Ui>. The text below the picker says which fields the source offers.

   <Screenshot src={shot_when_created} alt="The trigger A record is created with the data source Sicherheitsvorfälle" caption="The card's heading now reads A record is created · Sicherheitsvorfälle." />

</Steps>

## Add the condition

Without a condition, the automation would run for every new incident. This one should only run for critical ones.

<Steps>

1. In the card <Ui>Only if</Ui>, click <Ui>Condition</Ui>.

2. Pick the field <Ui>Schwere</Ui> (severity), the comparison <Ui>is</Ui> and the value <Ui>Kritisch</Ui>.

   <Screenshot src={shot_only_if} alt="The card Only if with the condition Schwere is Kritisch" caption="One condition. The heading of the card reads it back." />

</Steps>

For more than one condition, click <Ui>Condition</Ui> again. With two or more, a selector appears above them: <Ui>all</Ui> of them must hold, <Ui>at least one</Ui>, <Ui>none</Ui> or <Ui>not all</Ui>. <Ui>Group</Ui> nests conditions inside each other, for "status is open and (impact at least 4 or likelihood at least 4)". [Conditions](/automations/conditions/) explains all of it.

## Add the steps

The steps live in the card <Ui>Then</Ui>. They run from top to bottom.

<Steps>

1. Click <Ui>Step</Ui> and pick <Ui>Notify</Ui>.

   <Screenshot src={shot_step_menu} alt="The menu of the Step button with Notify, Send mail, Run an action and If / else" caption="The four kinds of step that ship with nexxus." />

2. Under <Ui>To</Ui>, leave the box with the name of the person it runs as unticked (here <Ui>Jana Brandt, who it runs as</Ui>) and pick Tom Keller under <Ui>Further people</Ui>.

3. Under <Ui>Notify by</Ui>, pick <Ui>Bell and e-mail</Ui>. A critical incident should not wait for the daily digest.

4. Under <Ui>Title</Ui>, type `Critical incident: ` and then open the menu <Ui>Insert placeholder</Ui> (the braces next to the field). Pick <Ui>Record name</Ui>. The title now reads `Critical incident: {{record.title}}`, and every notification carries the name of the incident that triggered it.

   <Screenshot src={shot_placeholder_menu} alt="The placeholder menu next to the title, with the name, link and id of the record and every field of the source" caption="Insert placeholder offers the fixed values and every field of the source." />

5. Under <Ui>Text</Ui>, write `Detected on {{record.detectedAt}}. Please assess within one hour: {{record.link}}`. `{{record.link}}` becomes a link that opens the incident.

6. Click <Ui>Step</Ui> again and pick <Ui>Run an action</Ui>. Under <Ui>Action</Ui>, pick <Ui>Aufgabe anlegen (workspaceItem.create)</Ui> (create a task).

7. Fill in the fields of the action. <Ui>Name</Ui> is required: `Assess incident: {{record.title}}`. With <Ui>Field</Ui> you add the others:
   - <Ui>Board</Ui>: the number of the board. It is the number at the end of the board's address, `/workspace/board/2`.
   - <Ui>Priorität</Ui> (priority): `high`. The allowed values are `critical`, `high`, `normal`, `low` and `minor`, written in lower case.
   - <Ui>Zuständig</Ui> (assignee): the number of the person. The person pickers show it in brackets, `[3] Tom Keller`.

   <Screenshot src={shot_action_step} alt="The step Run an action with the action Aufgabe anlegen and the fields Name, Board, Priorität and Zuständig" caption="An action runs without asking, with the rights of the person the automation runs as." />

8. Click <Ui>Step</Ui> a third time and pick <Ui>Send mail</Ui>. Under <Ui>To</Ui>, enter `management@example.com`. Several addresses are separated by commas. Fill in <Ui>Subject</Ui> and <Ui>Text</Ui>; both take placeholders too.

   <Screenshot src={shot_then_steps} alt="The card Then with three steps: Notify, Run an action and Send mail" caption="The finished card Then. The arrows on each step move it up or down; the bin removes it." />

</Steps>

## Check and test it

<Steps>

1. Read the sentence under <Ui>In one sentence</Ui> at the bottom of the editor. It describes the whole automation. If it says what you meant, the automation is built the way you meant it.

   <Screenshot src={shot_summary} alt="The sentence In one sentence below the editor" caption="The sentence is written by the server and is in German for now: when a record in Sicherheitsvorfälle is created, and only if Schwere is Kritisch, notify one person, create a task and send a mail." />

2. Open the tab <Ui>Test run</Ui> and click <Ui>Start test run</Ui>. nexxus tries the automation against your real data without saving or changing anything. Actions only pass their pre-check, and notifications and mails are only prepared.

   The result says how often the automation would have run in the last 7 days, shows the steps for up to 3 matching records, and lists the notifications that would go out.

   <Screenshot src={shot_test_run} alt="The test run: it would have run 3 times in the last 7 days, the steps for three incidents and the notification that would go out" caption="Each step shows test: nothing was changed. The preview gathers the three sample incidents in one notification." />

3. Go back to the tab <Ui>Edit</Ui> and click <Ui>Create automation</Ui>. It is switched on right away.

</Steps>

From now on, every critical incident starts a run. You find each run with the result of every step in the tab <Ui>History</Ui>; see [Test run and history](/automations/test-and-history/).

## What happens behind the scenes

- **Within seconds.** nexxus notes every saved change to a record and the job `AUTOMATION_EVENTS` hands it to the automations listening to that source, every 2 seconds. A change that is rolled back triggers nothing, and imports trigger nothing.
- **The condition is checked when the run starts**, not when the record was saved. If someone corrects the severity within those seconds, the automation sees the corrected value.
- **One run per record.** Ten critical incidents created at once give ten runs and ten notifications for Tom. Triggers that find several records in one go, a schedule or a condition, gather them into one notification per person instead; see [Steps and placeholders](/automations/steps/#notify).
- **A failed step stops the run.** If the task cannot be created, the mail is not sent. The history shows which step failed and why. Five failed runs in a row pause the automation.

## When something goes wrong

| What you see | What it means |
|---|---|
| <Ui>Record triggers do not run yet: a superadmin has to switch on the cron job "AUTOMATION_EVENTS" (Settings › Operations › Maintenance › Cron Jobs).</Ui> | The automation is saved but does not react to new records until the job is on. |
| <Ui>A condition still lacks its value.</Ui> | A condition row has a field and a comparison but no value. |
| <Ui>A notification needs someone to receive it.</Ui> | The step <Ui>Notify</Ui> has nobody under <Ui>To</Ui>. |
| <Ui>It does not run like this</Ui> in the test run | A step would fail with the current form. The message below says why. |
| A run in the history shows <Ui>failed</Ui> | The failed step carries the reason, in German. <Ui>Priorität 'HIGH' gibt es nicht. Erlaubt: critical, high, normal, low, minor</Ui> means the priority was written in capitals; the allowed values follow. Fix the step and click <Ui>Save</Ui>. |
| The history shows the notify step as <Ui>succeeded</Ui> with <Ui>Niemand, der die Meldung bekommen darf.</Ui> | Nobody under <Ui>To</Ui> may read the record, or the people are deactivated. The step counts as done, but no notification went out. Check the rights of the recipients. |

## Next steps

<CardGrid>
  <LinkCard title="Triggers" href="/automations/triggers/" description="React to changes of single fields, to counts that cross a threshold, or run on a schedule." />
  <LinkCard title="Steps and placeholders" href="/automations/steps/" description="Every step in detail, if and else, and the full list of placeholders." />
  <LinkCard title="Recipes" href="/automations/recipes/" description="Five more automations to copy." />
</CardGrid>