---
title: "Notification recipients and content"
site: admin
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/admin/1.11/messaging/notification-recipients-and-content/
type: reference
application: system_email
last_updated: 2026-10-18
commit: a8c06bf830ed
---


This page collects the script patterns an outbound notification uses: who receives it, what the subject and body say, and what a script can pass in. It is for administrators and developers writing the script fields described in [Outbound notifications](page:messaging/outbound-notifications).

## Script fields and where they live

| Field | Enhanced Notifications (v2) | Classic Email Notifications (v1) | Sets `answer` to |
| --- | --- | --- | --- |
| **Condition** | Notification | Notification | True or false |
| **Recipients** | Notification | Notification | An array of recipients |
| **Context script** | Notification and provider configuration | Notification | An object of named values |
| **Messaging account** | Provider configuration | Notification | A messaging account ID |
| **From** | Provider configuration | Notification | A sender address |
| **Subject**, body | Messaging template (**Subject**, **HTML Template**) | Notification (**Subject**, **Body**) | Not a script. Text with substitutions. |

Every script can read `current`, the record the notification runs for. The `OutboundNotificationSupport` script library has `fromAddress(record)` and `messagingAccount(record)` functions you can fill in to set both values for every notification in one place.

## Recipients

**Recipients** must end by assigning an array to `answer`. An entry can be an email address, a string field holding an address, a user reference or a multiple reference to users. Servicely uses each user's email address and sends each address one message.

| Entry | Example | Resolves to |
| --- | --- | --- |
| Fixed address | An address in quotes | That address |
| String field | `current.Email()` | The address in the field |
| User reference | `current.Requestor()` | The user's email address |
| Multiple reference | `current.relation("Follower")` | Each user's email address |
| CC recipient | `cc(current.Requestor())` | A CC address. Ignored when **Send individually** is on. |
| BCC recipient | `bcc(current.relation("SecretFollower"))` | A BCC address. Ignored when **Send individually** is on. |

### Combine sources

```javascript
let toList = [
    current.relation("Follower"),
    current.RequestedFor(),
    current.Email()
];

if (current.Assignee()) {
    toList.push(current.Assignee());
}

answer = toList;
```

### Add the members of follower groups

`FollowerGroups` here is a multiple reference to groups. The script adds every active member of each group.

```javascript
let toList = [];
let groupIds = current.getRelation("FollowerGroups").map(group => group.ID());

for (let i = 0; i < groupIds.length; i++) {
    let userRec = Table("User")
        .SUBQUERY("Group", EQUAL("Id", groupIds[i]))
        .EQUAL("Active", true)
        .query();
    while (userRec.next()) {
        toList.push(userRec.Email());
    }
}

answer = toList;
```

## Subject and body

The subject and body mix HTML, field substitutions and context values. To edit the body's HTML directly, select the source-code button on the editor toolbar.

<Image src="asset:screenshots/admin/messaging-outbound-notifications/image-5.png">The body editor toolbar with the source-code button at its right end highlighted.</Image>

| Substitution | Example | Behaviour |
| --- | --- | --- |
| Field of the record | `${current.ShortDescription()}` | Shows the field's value. An empty field shows nothing. |
| Field of a related record | `${current.Requestor().Manager()}` | Shows nothing if any reference on the way is empty |
| Journal field | `${current.ClientJournal()}` | Shows only the latest entry, or nothing |
| Context value | `${requestor_mobile}` | Shows the value the context script returned under that name |
| Script context | `${context.emailSubject}` | Shows a value passed by the script that sent the notification |

## Context script

A context script runs before the message is built and returns named values for the subject and body.

```javascript
let requestor = current.Requestor();

answer = {
    requestor_mobile: requestor.Mobile.hasValue() ? requestor.Mobile() : "User does not have a mobile"
};
```

<Image src="asset:screenshots/admin/messaging-outbound-notifications/image-6.png">A notification body that uses ${current.ShortDescription()} and ${requestor_mobile}.</Image>

### Link back to the record

`getLinkForUI` returns a link that opens the record in the named aspect, here SelfService.

```javascript
answer = {
    record_url: current.getLinkForUI({create: false, aspect: "SelfService"})
};
```

Then use the value in the HTML body:

```html
<p><a href="${record_url}">View the ticket</a></p>
```

## Attachments

To attach files, return an `attachmentIds` array of Attachment record IDs from the context script. Keep any other values in the same object.

```javascript
const pdfIds = current.Attachments()
    .filter(rec => rec.MimeType().endsWith("pdf"))
    .map(rec => rec.getID());

answer = {
    attachmentIds: pdfIds
};
```

<!-- source: system_email/data/ApplicationProperty?Key=notification.email.add.inline.attachments -->
| Property | Default | Behaviour |
| --- | --- | --- |
| `notification.email.add.inline.attachments` | false | When true, attachment links in the body, other than images, also attach the file to the email |

## Scripted notifications and context

A trigger, workflow or job can send a notification with `OutboundNotification.processDirectOutboundNotification`. The optional `context` object is available to every script field and substitution as `context`.

```javascript
let notificationRec = Table("OutboundNotification")
    .EQUAL("Name", "Incident - Has been resolved")
    .query();

if (notificationRec.next()) {
    OutboundNotification.processDirectOutboundNotification(notificationRec, current, {
        context: {
            emailRecipients: [current.Requestor()],
            emailSubject: current.Number(),
            bodyIntro: "Your incident has been resolved."
        }
    });
}
```

`current` is the record the notification runs for. In a job, query any record and pass it instead. The notification's scripts then read the context:

| Field | Script |
| --- | --- |
| **Recipients** | `answer = context.emailRecipients;` |
| **Messaging account** | `answer = context.messagingAccount;` |
| **From** | `answer = context.fromAddress;` |
| **Context script** | `answer = { texttosay: context.bodyIntro };` |
| **Subject** | `Incident ${context.emailSubject} updated` |

## Related

- [Outbound notifications](page:messaging/outbound-notifications)
- [Create an outbound notification](page:messaging/create-an-outbound-notification)
- [Classic (v1) notification fields](page:messaging/classic-notifications)
- [Script Libraries](page:automation/script-libraries)
