PreferenceDestination - Scoped, Global
-
- UpdatedJan 30, 2025
- 4 minutes to read
- Yokohama
- API reference
The PreferenceDestination API updates user notification preferences.
A notification destination is somewhere that a notification can be delivered to, such as a specific email address or phone number. This API is based on notifications from the Notification [sys_notification] table. Notifications are sent through channels such as email or Workspace. A channel can be used to send notifications to multiple types of destinations. For example, an email channel could send notifications to both personal email and work email destinations. Destination types are listed in the Notification Destination Type [sys_notif_destination_type] table.
A user can update their own notification preferences, and an admin can update notification preferences for any user. User notification preferences control which destinations will receive which notifications.
Use this API with the Preferences API. Before calling any methods in this class, you must call the Preferences.getDestinations() or Preferences.getDestinationsByChannel() methods to instantiate a PreferenceDestination object.
This class uses the
sn_notification
namespace identifier.
PreferenceDestination - getChannel()
Returns the channel that is used to send notifications to the destination.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideRecord | GlideRecord from the Notification Channel [sys_notification_channel] table for the channel that is used to send notifications to the destination. |
Example
This example prints the channel that is used to send notifications for each of Abel Tuter's destinations.
Output:
PreferenceDestination - getDeliverTo()
Returns the identifier for the destination.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Identifier for the destination. For example, an email address, push application install token, or sys_id. |
Example
This example prints the identifier for each of Abel Tuter's destinations. The output shows that the identifier for Abel's Workspace destination is the user sys_id.
Output:
PreferenceDestination - getDestinationType()
Returns the type of destination, such as personal email or work email.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideRecord | GlideRecord from the Notification Destination Type [sys_notif_destination_type] table for the destination type. |
Example
This example prints the identifier for each of Abel Tuter's destinations. The output shows that the identifier for Abel's Workspace destination is the user sys_id.
Output:
PreferenceDestination - isActive(GlideRecord notification)
Checks if the destination has permission to receive a notification.
Name | Type | Description |
---|---|---|
notification | GlideRecord | Optional. Notification to check if the destination has permission to receive that notification. An exception is thrown if the notification doesn't exist or if the notification isn't readable by the destination's user. If no notification is specified, this method checks if the destination has permission to receive any notifications. |
Type | Description |
---|---|
Boolean | Flag that indicates whether the destination has permission to receive a notification. Possible values:
|
Example
This example checks if each of Abel Tuter's destinations has permission to receive the Approval Request notification.
Output:
PreferenceDestination - isOverriden(GlideRecord notification)
Checks if a notification overrides a user's preferences for the destination.
Name | Type | Description |
---|---|---|
notification | GlideRecord | Specify a notification to check if it overrides user preferences for the destination. The notification should be a GlideRecord from the Notification [sys_notification] table. |
Type | Description |
---|---|
Boolean | Flag that indicates whether the notification overrides user preferences for the destination. Valid values:
|
Example
This example checks if the Approval Request notification overrides user preferences for one of Abel Tuter's destinations. If the notification doesn't override user preferences, the destination is given permission to receive the notification. Otherwise, no preference is set because the notification overrides the preference.
PreferenceDestination - setActive(GlideRecord notification, Boolean active)
Sets the user preference for a destination to receive or not receive notifications.
The isOverriden() method can be called first to check if the user preference will be ignored, but it is not required.
Name | Type | Description |
---|---|---|
notification | GlideRecord | Optional. If a notification is specified, the user preference is set for the destination to receive or not receive that notification. The notification should be a GlideRecord from the Notification [sys_notification] table. If no notification is specified, the user preference is set for the destination to receive or not receive all notifications. |
active | Boolean | Flag that indicates whether the destination has permission to receive a notification. Valid values:
|
Type | Description |
---|---|
None |
Example
This example checks if the Approval Request notification overrides user preferences for one of Abel Tuter's destinations. If the notification doesn't override user preferences, the destination is given permission to receive the notification. Otherwise, no preference is set because the notification overrides the preference.
On this page
- PreferenceDestination - getChannel()
- PreferenceDestination - getDeliverTo()
- PreferenceDestination - getDestinationType()
- PreferenceDestination - isActive(GlideRecord notification)
- PreferenceDestination - isOverriden(GlideRecord notification)
- PreferenceDestination - setActive(GlideRecord notification, Boolean active)