Automatiseringsregels

Automation rules are used to trigger automatic changes based on user actions (e.g., apply a modification when a field is set to a specific value), email events, time conditions (e.g., archive a record 7 days after its last update), or external events.

To create an automation rule with Studio, proceed as follows:

  1. Open Studio en klik op Automatiseringen, vervolgens op Nieuw.

  2. Select the Activeren and, if necessary, fill in the fields that appear on the screen based on the chosen trigger.

  3. Klik op Actie toevoegen, selecteer vervolgens het Type van actie en vul de velden in die op het scherm verschijnen op basis van je geselecteerde actie.

  4. Klik op Opslaan & Sluiten of Opslaan & Nieuw.

Example

Example of an automated action on the Subscription model

Tip

  • To modify the model of the automation rule, switch models before clicking Automations in Studio, or activate the developer mode, create or edit an automation rule, and select the Model in the Automation Rules form.

  • You can also create automation rules from any kanban stage by clicking the gear icon ( ) next to the kanban stage name, then selecting Automations. In this case, the Trigger is set to Stage is set to by default, but you can change it if necessary.

    Automatiseringen maken vanuit een kanban-fase

Activeren

The Trigger is used to define when the automation rule should be applied. The available triggers depend on the model. Five trigger categories are available overall:

Tip

You can also define a Before Update Domain to specify the conditions that must be met before the automation rule is triggered. In contrast, the conditions defined using the Extra Conditions and Apply on filters are checked during the execution of the automation rule.

To define a Before Update Domain, activate the developer mode, create or edit an automation rule, click Edit Domain, then click New Rule.

For example, if you want the automated action to happen when an email address is set on a contact that did not have an address before (in contrast to modifying their existing address), define the Before Update Domain to Email is not set, and the Apply on domain to Email is set.

Voorbeeld van een trigger met een Before Update Domain

Waarden geüpdatet

The triggers available in this category depend on the model and are based on common field changes, such as adding a specific tag (e.g., to a task) or setting the User field. Select the trigger, then select a value if required.

Example of a Values Updated trigger

E-mail gebeurtenissen

Automatische acties activeren bij het ontvangen of verzenden van e-mails.

Timing Voorwaarden

Trigger automated actions based on a date field. The following triggers are available:

  • Based on date field: Select the field to be used next to the Delay field.

  • After creation: The action is triggered when a record is created and saved.

  • After last update: The action is triggered when an existing record is edited and saved.

Je kunt dan definiëren:

  • a Delay: Specify the number of minutes, hours, days, or months. To trigger the action before the trigger date, specify a negative number. If you selected the Based on date field trigger, you must also select the date field to be used to determine the delay.

  • Extra Conditions: Click Add condition, then specify the conditions to be met to trigger the automation rule. Click New Rule to add another condition.

The action is triggered when the delay is reached and the conditions are met.

Example

If you want to send a reminder email 30 minutes before the start of a calendar event, select the Start (Calendar Event) under Trigger Date and set the Delay to -30 Minutes.

Voorbeeld van een trigger op basis van datumveld

Notitie

By default, the scheduler checks for trigger dates every 4 hours, meaning lower granularity in time-based automations may not always be honored.

Aangepast

Automatische acties activeren:

  • On save: When the record is saved;

  • On deletion: When a record is deleted;

  • On UI change: When a field’s value is changed on the Form view, even before saving the record.

Voor de triggers Bij opslaan en Bij wijziging gebruikersinterface moet je vervolgens het veld of de velden selecteren die gebruikt worden om de automatiseringsregel te activeren in het veld Bij bijwerken.

Waarschuwing

Als er geen veld is geselecteerd in het veld Bij bijwerken, kan de automatische actie meerdere keren per record worden uitgevoerd.

Optioneel kun je ook aanvullende voorwaarden definiëren die moeten worden voldaan om de automatiseringsregel te activeren in het veld Toepassen op.

Notitie

The On UI change trigger can only be used with the Code uitvoeren action and only works when a modification is made manually. The action is not executed if the field is changed through another automation rule.

Extern

Trigger automated actions based on an external event using a webhook. A webhook is a method of communication between two systems where the source system sends an HTTP(S) request to a destination system based on a specific event. It usually includes a data payload containing information about the event that occurred.

To configure the On webhook trigger, copy the URL generated by Odoo into the destination system (i.e., the system receiving the request). Then, in the Target Record field, enter the code to run to define the record(s) to be updated using the automation rule.

Waarschuwing

The URL must be treated as confidential; sharing it online or without caution could potentially expose your system to malicious parties. Click the Rotate Secret button to change the URL’s secret if necessary.

Notitie

  • The code defined by default in the Target Record field works for webhooks coming from another Odoo database. It is used to determine the record(s) to be updated using the information in the payload.

  • If you wish to use the webhook’s content for a purpose other than to find the record(s) (e.g., create a record), your only option is to use an Code uitvoeren action. In this case, the Target record field must contain any valid code, but its result doesn’t have any effect on the automated action itself.

  • The webhook content is available in the server action context as a payload variable (i.e., a dictionary that contains the GET parameters or POST JSON body of the incoming request).

You can also choose to Log Calls to record the payloads received, e.g., to make sure the data sent by the source system matches the expected format and content. This also helps identify and diagnose any issues that may arise. To access the logs, click the Logs smart button at the top of the Automation rules form.

Te doen acties

Once you have defined the automation rule’s trigger, click Add an action to define the action to be executed.

Tip

You can define multiple actions for the same trigger/automation rule. The actions are executed in the order they are defined. This means, for example, that if you define an Update record action and then a Send email action, the email uses the updated values. However, if the Send email action is defined before the Update record action, the email uses the values set before the update action is run.

Record bijwerken

This action allows to update one of the record’s (related) fields. Click the Update field and, in the list that opens, select or search for the field to be updated; click the right arrow next to the field name to access the list of related fields if needed.

Als je een veel-op-veel-veld hebt geselecteerd, kies dan of het veld moet worden bijgewerkt door de geselecteerde waarde Toe te voegen, te Verwijderen, of door deze In te stellen op of door het te Wissen.

Example

If you want the automated action to remove a tag from the customer record, set the Update field to Customer > Tags, select By Removing, then select the tag.

Voorbeeld van een Update Record-actie

Tip

Je kunt het veld van een record ook dynamisch instellen met Python-code. Selecteer hiervoor Berekenen in plaats van Bijwerken, en voer vervolgens de code in die moet worden gebruikt voor het berekenen van de veldwaarde. Als je bijvoorbeeld wilt dat de automatiseringsregel een aangepast datum- en tijdveld berekent wanneer de prioriteit van een taak wordt ingesteld op Hoog (door de taak te sterren), kun je de trigger Prioriteit is ingesteld op Hoog definiëren en de actie Record bijwerken als volgt definiëren:

Een aangepast datetime-veld berekenen met een Python-expressie

Activiteit maken

Deze actie wordt gebruikt om een nieuwe activiteit te plannen die aan het record is gekoppeld. Selecteer een Activiteitstype, voer een Titel en beschrijving in, specificeer vervolgens wanneer je de activiteit wilt plannen in het veld Vervaldatum over, en selecteer een Gebruikerstype:

  • To always assign the activity to the same user, select Specific User and add the user in the Responsible field;

  • Om dynamisch een gebruiker te targeten die aan het record is gekoppeld, selecteer je Dynamische gebruiker (op basis van record) en wijzig je indien nodig het Gebruikersveld.

Example

Nadat een lead is omgezet in een verkoopkans, wil je dat de geautomatiseerde actie een oproep inplant voor de gebruiker die verantwoordelijk is voor de lead. Stel hiervoor het Activiteitstype in op Oproep en het Gebruikerstype op Dynamische gebruiker (op basis van record).

Voorbeeld van een Create Activity-actie

E-mail verzenden en sms verzenden

Deze acties worden gebruikt om een e-mail of een sms te verzenden naar een contactpersoon die is gekoppeld aan een specifiek record. Selecteer of maak hiervoor een E-mailsjabloon of een Sms-sjabloon, en kies vervolgens in het veld E-mail verzenden als of Sms verzenden als hoe je de e-mail of sms wilt verzenden:

  • E-mail: om het bericht als e-mail te verzenden naar de ontvangers van het E-mailsjabloon.

  • Bericht: om het bericht op het record te plaatsen en de volgers van het record op de hoogte te stellen.

  • Notitie: om het bericht als interne notitie te verzenden die zichtbaar is voor interne gebruikers in de chatter.

  • Sms (zonder notitie): om het bericht als tekstbericht te verzenden naar de ontvangers van het sms-sjabloon.

  • Sms (met notitie): om het bericht als tekstbericht te verzenden naar de ontvangers van het sms-sjabloon en het als interne notitie in de chatter te plaatsen.

  • Alleen notitie: bericht alleen als interne notitie in de chatter plaatsen.

Volgers toevoegen en verwijderen

Use these actions to (un)subscribe existing contacts to/from the record.

Record maken

Deze actie wordt gebruikt om een nieuw record te maken op elk model.

Selecteer het vereiste model in het veld Te maken record; dit bevat standaard het huidige model. Specificeer een Naam voor het record, en selecteer vervolgens, als je het record op een ander model wilt maken, een veld in het veld Koppelingsveld om het record dat de aanmaak van het nieuwe record heeft geactiveerd te koppelen.

Notitie

De vervolgkeuzelijst gerelateerd aan het veld Koppelingsveld bevat alleen een-op-veel-velden die bestaan op het huidige model en die zijn gekoppeld aan een veel-op-een-veld op het doelmodel.

Tip

You can create another automation rule with Record bijwerken actions to update the fields of the new record if necessary. For example, you can use a Create Record action to create a new project task and then assign it to a specific user using an Update Record action.

Code uitvoeren

Deze actie wordt gebruikt om Python-code uit te voeren. Je kunt code schrijven in het tabblad Code met de volgende variabelen:

  • env: omgeving waarin de actie wordt geactiveerd

  • model: model van de record waarop de actie wordt geactiveerd; is een lege recordset

  • record: record waarop de actie wordt geactiveerd; kan leeg zijn

  • records: recordset van alle records waarop de actie wordt geactiveerd in multi-modus; kan leeg blijven

  • time, datetime, dateutil, timezone: handige Python-bibliotheken

  • float_compare: hulpfunctie om floats te vergelijken op basis van specifieke precisie

  • log(message, level='info'): logfunctie om debug-informatie vast te leggen in ir.logging-tabel

  • _logger.info(message): logger om berichten te versturen in serverlogs

  • UserError: exceptieklasse voor het tonen van waarschuwingsberichten aan gebruikers

  • Command: x2many-opdrachten namespace

  • action = {...}: om een actie te retourneren

Tip

De beschikbare variabelen worden beschreven in de tabbladen Code en Help.

Webhook notificatie verzenden

This action allows to send a POST request with the values of the Fields to the URL specified in the URL field.

De Voorbeeldpayload toont een voorbeeld van de gegevens in het verzoek op basis van een willekeurige record of dummygegevens als er geen record beschikbaar is.

Bestaande acties uitvoeren

De actie wordt gebruikt om meerdere acties (gekoppeld aan het huidige model) tegelijkertijd te activeren. Klik hiervoor op Regel toevoegen, en selecteer vervolgens in de pop-up Toevoegen: Onderliggende acties een bestaande actie of klik op Nieuw om een nieuwe te maken.