## Business rules

Business rules automate actions performed on issues based on defined conditions — without manual user intervention.

Configuration is available under **Configuration → Issue types → [type] → Business rules**.

![Business rules](/rkl-business-rules-en.jpg)

## Rule structure

Each rule has three configuration sections:

- **General** — triggering event, name, description, and active status
- **Conditions** — optional filtering criteria
- **Actions** — operations executed automatically when the conditions are met

## Trigger events

A rule fires when the selected event occurs:

| Event | Description |
|---|---|
| Issue created | A new issue has been saved in the system |
| Issue updated | Any change was made to the issue |
| Issue assigned to user | The assignee of the issue changed |
| Issue step changed | The issue moved to a different step |
| Incoming email assigned to issue | An email was attached to the issue |
| Issue updated via remote form | A customer updated the issue through a remote form |
| Issue created from Allegro return | An issue was created from an Allegro return ([Allegro Returns](/integrations/allegro-returns)) |
| Allegro return status changed | The status of the Allegro return linked to the issue changed |

On accounts with the [Service add-on](/service), the **Service** group also offers job events (described in [Service jobs](/service/jobs#business-rules)) and quote events: **Quote sent**, **Quote accepted**, **Quote rejected** and **Quote reminder** (described in [Quotes](/service/quotes#business-rules)).

## Conditions

Conditions restrict rule execution to issues that meet specific criteria. Two types are available:

- **Required conditions** — all defined conditions must be met simultaneously
- **Optional conditions** — it is enough for one condition to be met

Available condition types:

| Condition | Description |
|---|---|
| Process - operation executed | Checks which operation triggered the step change |
| Issue - distributor | Checks the distributor assigned to the issue |
| Issue - customer | Checks the customer assigned to the issue |
| Issue - service | Checks the service assigned to the issue |
| Issue - step | Checks the current step of the issue |
| Issue - status | Checks the current status of the issue |
| Issue - assigned user | Checks the assigned user |
| Issue - product | Checks the product linked to the issue |
| Issue - field value | Checks the value of a selected application field |
| Issue - issue source | Checks the origin of the issue (email, form, system, Allegro return) |
| Allegro return status | Checks the return status in Allegro events (**equals** / **does not equal** only) |

Other conditions support the operators: **equals**, **does not equal**, **contains**, **does not contain**.

## Actions

Actions are executed automatically when the event occurs and the conditions are satisfied. Multiple actions can be added to a single rule.

| Action | Description |
|---|---|
| Send email | Sends an email using a selected template; PDF templates can be attached |
| Send SMS | Sends an SMS via a selected provider (SerwerSMS, SMSAPI) using a template |
| Assign issue to user | Sets the selected user as the assignee |
| Reset income date | Shifts the income date by a given number of days (resets the deadline counter) |
| Set field | Sets a selected issue field to a given value (see below) |
| Sending webhook | Sends issue data to an external system or messenger (Slack, Google Chat, Teams) — see below |

### Set field

The **Set field** action automatically does what a user could do manually in the issue edit form: it writes a configured value into a selected field. It replaces the former *Set customer*, *Set distributor*, and *Set service* actions — existing rules using them were migrated automatically.

You can set fields that are active and editable in the issue type, of these kinds: text, multi-line text, number, date, checkbox, select (single and multiple), radio, priority, category, and customer, distributor, and service. Products, files, step and status (handled by the workflow), and fields with a constant value cannot be set.

For date fields you choose the **Date type**:

- **Specific date** — a fixed date entered in the rule
- **Dynamic date** — calculated when the rule runs, e.g. *today*, *tomorrow*, *first day of next month*, *last day of the current week*

Both can have an **Offset (days, ±)** — e.g. "today + 14" sets a deadline two weeks after the event. Dates are calculated in the account's time zone.

The action does not trigger the *Issue updated* event, so it does not fire further rules. If the field is later disabled in the issue type or the value no longer matches the list options, the action is skipped and the error is written to the [system log](/logs/system).

### Sending webhook

The action sends a request with a JSON body to the chosen [webhook](/integrations/webhooks). You choose:

- **Webhook** — where to send (the list of active webhooks from **System → Webhooks**),
- **Webhook template** — what to send (a template of type *Webhook*, see [Templates](/config/templates#webhook-template)).

The action works for every trigger event. Sending happens in the background — it does not delay saving the issue, and failed attempts are retried. The issue history gets an entry that the rule ran, and the result of each attempt is written to the [system log](/logs/system) (WEBHOOK module). If the template does not produce valid JSON, nothing is sent and the log gets a `WEBHOOK_INVALID_PAYLOAD` error.

The action requires the **Business** plan.

### Message recipients (email and SMS)

For message-sending actions, the following recipient options are available:

- **Assigned user** — the currently assigned person
- **Issue creator** — the person who created the issue
- **Distributor / Customer / Service** — the contact linked to the issue
- **Custom recipients only** — addresses entered manually

---

## FAQ

### Do business rules execute in real time?
Yes. Rules trigger immediately when the triggering event occurs.

### Can a rule be disabled without deleting it?
Yes. Each rule can be deactivated with the **Active** toggle — the rule is saved but not triggered.

### What is the difference between required and optional conditions?
**Required conditions** work like logical AND — all must be met. **Optional conditions** work like logical OR — one is enough. Both types can be used together in the same rule.

### Can multiple actions be added to one rule?
Yes. A single rule can have any number of actions, which are executed one after another.

### Can a rule send an email with a PDF attachment?
Yes. In the **Send email** action you can select PDF templates that will be attached to the message.
