# Trigger

## Business Rule Fields

{% hint style="warning" %}
When configuring a Trigger (Business Rule) on a table to be integrated, make sure one doesn’t exist already. If you have more than one, you will make duplicate updates.
{% endhint %}

In the **native ServiceNow** window, navigate to **System Definition > Business Rules > New**.

The Business Rule fields to be configured are as follows:

|  #  | Field    | Description                                            | Value                  |
| :-: | -------- | ------------------------------------------------------ | ---------------------- |
|  1  | Name     | The name of the business rule.                         | \<Your Name>           |
|  2  | Table    | The table that this business rule will run on.         | ‘Incident’ \[incident] |
|  3  | Active   | Set to true to enable this business rule.              | \<true>                |
|  4  | Advanced | Set to true to reveal the advanced version o the form. | \<true>                |

*The top section of your Business Rule record should look like this:*

![](/files/-MQmBa4eI_q-Jud9jVpj)

## 'When to run' Tab Fields

Click on the **When to run** tab and configure the fields as follows:

|  #  | Field  | Description                                                                                     | Value           |
| :-: | ------ | ----------------------------------------------------------------------------------------------- | --------------- |
|  5  | When   | When this business rule should execute relative to the database operation.                      | 'Before'        |
|  6  | Insert | Select this check box to execute the business rule when a record is inserted into the database. | \<true>         |
|  7  | Update | Select this check box to execute the business rule when a record is update.                     | \<true>         |
|  8  | Order  | The sequence in which this business rule should run.                                            | '1,000,000,000' |

*Your 'When to run' tab should look like this:*

![](/files/-MQmByFNL2qXEGpZYlBF)

## 'Advanced' Tab Fields

Click on the **Advanced** tab and configure the fields as follows:

|  #  | Field    | Description        | Value                                                                                                                                                                                     |
| :-: | -------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|  9  | Script\* | The script to run. | Replace the entire contents of the script field with your business rule code, ***substituting the name of your business rule** (see below)*. E.g. 'Business rule: Unifi Incident Trigger' |

*\*Script:*

The code in the script field should look like this:

```javascript
(function executeRule(current, previous /*null when async*/) {

    x_snd_eb.snd_console.execute('Business rule: Unifi Incident Trigger', function () {
        x_snd_eb.ActivityLog.setDocument(current, current.getTableName());
        x_snd_eb.Message.processOutbound(current);
    });

})(current, previous);
```

*Your 'Advanced' tab should look like this:*

![](/files/-MQmCS89vPRCiJ64lUVR)

10\) Click **Submit**.

The main elements are now in place for our Integration to work. We are now ready to configure and test each of our **Scenarios** in turn.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sharelogic.com/unifi/2.2/integration-guides/outbound-incident-guide/trigger.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
