> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Triggers

> Triggers

<Note>
  This feature requires a license for [Development Tools][1] or the CRM Suite **Core** plan.
</Note>

[1]: /en/admin/license/expander-services

Triggers are scripts that are executed for specific events in the system, such as when a new sale is created or a request gets closed. Triggers can react silently to what happens, or block the operation and show an explanation back to the user.

CRMScript can make your working day more efficient by automating various tasks. You can define that a certain event in the system will set in motion (trigger) one or more predefined actions. No knowledge of scripting is required to get this to work.

**Example from SuperOffice**: When a request is closed, the customer must be notified of this by email. We can create a macro that contains a series of actions to create and send this email notification. This macro is run automatically when a request is closed. The actions in the macro will load the relevant request, fetch the right reply template and send an email to the customer that the request is closed.

This is an example of a very simple trigger. You can for instance add conditions to the actions in a trigger, by changing the default **Always** setting.

## Create a trigger

We will now create a series of actions based on the example above.

1. Go to **Settings and maintenance**.
2. Click <i class="ph ph-code-block" aria-hidden="true" /> **CRMScript** and select the **Triggers** tab.
3. Click the **New trigger (macro)** button. The **Choose trigger** screen displays the available triggers. These are events in the system that can be used to set off actions/macros. In our example we select **Request closed**, so that the macro is run when a request is closed in SuperOffice.
4. Type "request" in the search field and select the trigger called **Request closed**.
5. Enter a description of the trigger in the **Description** field.
6. Select **Enabled**.
7. Select **Change a request** under **Choose action type** below. This takes you to the **Change a request** tab.
   This is the first action in the macro. It fetches the request, so that the various values (ID, title, contact name and so on) can be used in the next actions we will create.
8. Optional: Check **Internal message**, and enter, for example: "Request closed and confirmation sent to customer."
9. Click **Apply**.
10. Click **New action** next to the **Change a request** tab.
11. Select **Load a reply template for merging**. We will now fetch the reply template to be used.
12. Click the **Reply template** field, and select an existing reply template from the list shown, such as "Request closed".
13. Click **Apply**.
14. Click **New action**, and select **Send an email or SMS**. We will now adapt the email that will be sent to the customer.
15. Check **Subject**.
16. Click <i class="ph ph-gear" aria-label="Gear" /> to the right, and then click the **Choose parameter** field.
17. Select **Change a request** > **Title**. This will put the request title in the subject of the email.
18. Check **From** and select **Change a request** > **Owner**.
19. Check **To** and select **Change a request** > **Contact: Email address**.
20. Check **HTML message** and select **Load a reply template for merging** > **HTML text**.
21. Click **Apply**.

You have now created a macro that sends an email with "Request closed" to the customer when a request is closed. This trigger is active immediately if you checked **Enabled** at the top.


## Related topics

- [Trigger](/en/automation/trigger/reference/CRMScript.Event.Trigger.md)
- [Trigger scripts](/en/automation/trigger/reference/index.md)
- [Create a Trigger object](/en/api/web-services/howto/flows/rest-create-flow-trigger.md)
- [Creating a trigger :: Macro](/en/automation/trigger/create-trigger-macro.md)
- [NSWorkflowTrigger](/en/automation/crmscript/reference/CRMScript.NetServer.NSWorkflowTrigger.md)
- [Using dialogs in triggers](/en/automation/crmscript/tutorials/using-dialogs-in-triggers.md)
