# Trigger

## Business Rule

{% hint style="warning" %}
There is no need for you to manually create a Trigger (Business Rule). If you have more than one, you will make duplicate updates.
{% endhint %}

{% hint style="info" %}
Unifi will automatically create a Trigger (Business Rule) for the Process being integrated *(if one doesn't already exist)* when you run 'Build' either on the Integration or Message once your Create Message is configured.
{% endhint %}

In **native ServiceNow**, navigate to **System Definition > Busines Rules**. Find and navigate to the automatically generated Business Rule.

{% hint style="info" %}
The format of the name will be '\[S] Unifi ' + \<Table Name> + ' trigger rule'.
{% endhint %}

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-Mdc9g30AYARF6w3ScZK%2F-MdcI4rXAJBH8Ym2Jtse%2FBAIG%20-%20Trigger%201.png?alt=media\&token=3e09a2dc-c05d-4e43-ab64-24f010938754)

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

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MdcKBjmVR_l1Rr5uoAE%2F-MdvP3sKr2zdeiLOGu3G%2FBAIG%20-%20Trigger%202.png?alt=media\&token=0bf5fc19-04cf-4318-8034-b5f81d3cdedf)

## When to run Fields

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

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MdcKBjmVR_l1Rr5uoAE%2F-MdvPxKak9XZ3fdSIN9G%2FBAIG%20-%20Trigger%203.png?alt=media\&token=a80e8070-3952-4f0b-b21f-d12175162ab1)

## Advanced Fields

*The code in the script field should look like this:*

```javascript
(function executeRule(current, previous /*null when async*/) {
  x_snd_eb.ws_console.logExecute('Business rule: [S] Unifi ' + current.getTableName() + ' trigger rule', function () {
    x_snd_eb.ActivityLog.setDocument(current, 'sys_script');
    x_snd_eb.Message.processOutbound(current);
  });
})(current, previous);
```

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

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MdcKBjmVR_l1Rr5uoAE%2F-MdvRE-H1XtWnKOO5qGN%2FBAIG%20-%20Trigger%204.png?alt=media\&token=aa7ca128-3bee-4b53-add8-ba937bb73a39)

We have confirmed the main elements are in place for our Integration to work.  We are now ready to **Test** our **CreateIncident** Message.
