Skip to content

Content Script Extension for Notifications

Using the extension

This section describes how to use the notifications API to send messages to the Content Server Notification Center through Module Suite Extension for Notifications. The main service object is notifications, which provides methods for sending different types of notification messages and formatting rich content within them.

Sending a simple notification

def members  = [users.current]
def subject  = "Subject"
def message  = "This is a message"
def shortMex = "This is a short message"

notifications.sendMessage(members, subject, message, shortMex)

Sending different types of notifications

Notifications can be sent with different visual styles, each rendered with a distinct decoration in the Notification Center:

  • ErrorsendErrorMessage
  • AlertsendAlertMessage
  • ConfirmationsendConfirmationMessage
  • InformationsendInformationMessage
  • Default (message)sendMessage
notifications.sendErrorMessage(members, subject, message, shortMex)

notifications.sendAlertMessage(members, subject, message, shortMex)

notifications.sendConfirmationMessage(members, subject, message, shortMex)

notifications.sendInformationMessage(members, subject, message, shortMex)

Adding meaningful information to notifications

The Notification Center automatically retrieves information about nodes and users when the following tokens are included in the subject, short message, or message body:

Token Description
[node_NODEID] Replaced with the node name as a clickable link
[parentnode_NODEID] Replaced with the parent node location as a clickable link
[user_USERID] Replaced with the login name of the user
[csurl_PARAMKEY] Replaced with a clickable link to a Content Server address. The PARAMKEY must be a registered link

The extension provides convenient formatting methods to generate these tokens:

def nodeInfo     = notifications.formatNodeInfo(2000)
// returns [node_2000]

def locationInfo = notifications.formatLocationInfo(2000)
// returns [parentnode_2000]

def userInfo     = notifications.formatUserInfo(users.getUserById(1000))
// returns [user_1000]

def linkInfo     = notifications.formatLink("?func=user.listusers", "List Users")
// returns [csurl_<registered-key>]

You can also pass CSNode objects directly:

def node = docman.getNode(2000)

def nodeInfo     = notifications.formatNodeInfo(node)
def locationInfo = notifications.formatLocationInfo(node)

Using formatted content in a notification

def node    = docman.getNode(2000)
def user    = users.current
def subject = "Document uploaded"
def message = "The document ${notifications.formatNodeInfo(node)} was uploaded " +
              "by ${notifications.formatUserInfo(user)}"

notifications.sendMessage([user], subject, message, "Document uploaded")

Formatting key-value pairs

Use formatKeyValue to create a structured label-value pair inside notification messages:

def info = notifications.formatKeyValue("Status", "Approved")
// renders as a styled label + value block in the notification body

Changing the notification icon

All sendMessage methods accept a subjectDecoration parameter that controls the icon displayed alongside the notification in the Notification Center.

Accepted values:

Value Icon
[info] Information icon (default)
[user] User icon
[process] Gear / process icon
[node_NODEID] Icon of a specific node
def subjectDecoration = notifications.formatNodeInfo(2000)

notifications.sendMessage(members, subject, message, shortMex, subjectDecoration)

Aggregating notifications

Multiple notifications can be grouped into a single entry in the Notification Center by passing the fingerprint parameter. All messages sent with the same fingerprint value are collapsed together.

def members     = [users.current]
def subject     = "Subject"
def shortMex    = "This is a short message"
def fingerprint = "MY_AGGREGATE_KEY"

notifications.sendMessage(members, subject, "Message 1", shortMex, null, null, null, fingerprint)
notifications.sendMessage(members, subject, "Message 2", shortMex, null, null, null, fingerprint)
notifications.sendMessage(members, subject, "Message 3", shortMex, null, null, null, fingerprint)

When aggregated, the notification subject and short message shown are from the most recent notification in the group.

aggregateKey vs fingerprint

The aggregateKey parameter is used internally by the Notification Center and is not needed for aggregating notifications. Use the fingerprint parameter to group messages.

Setting notification expiration

All sendMessage methods accept an optional expirationDays parameter that controls how many days the notification remains visible before it is automatically removed from the Notification Center.

notifications.sendMessage(members, subject, message, shortMex, null, null, 7, null)

Notification service APIs

Method Summary
boolean
sendMessage(List<CSMember> recipients, String subject, String message, String shortMex, String subjectDecoration, String aggregateKey, Integer expirationDays, String fingerprint)
Sends a notification message to the specified recipients
boolean
sendAlertMessage(List<CSMember> recipients, String subject, String message, String shortMex, String subjectDecoration, String aggregateKey, Integer expirationDays, String fingerprint)
Sends an alert notification to the specified recipients
boolean
sendErrorMessage(List<CSMember> recipients, String subject, String message, String shortMex, String subjectDecoration, String aggregateKey, Integer expirationDays, String fingerprint)
Sends an error notification to the specified recipients
boolean
sendConfirmationMessage(List<CSMember> recipients, String subject, String message, String shortMex, String subjectDecoration, String aggregateKey, Integer expirationDays, String fingerprint)
Sends a confirmation notification to the specified recipients
boolean
sendInformationMessage(List<CSMember> recipients, String subject, String message, String shortMex, String subjectDecoration, String aggregateKey, Integer expirationDays, String fingerprint)
Sends an information notification to the specified recipients
String
formatKeyValue(String label, String value)
Formats a key-value pair for display in notification messages
String
formatNodeInfo(CSNode node)
Returns a [node_ID] token for the given CSNode
String
formatNodeInfo(Long nodeId)
Returns a [node_ID] token for the given node ID
String
formatLocationInfo(CSNode node)
Returns a [parentnode_ID] token for the given CSNode
String
formatLocationInfo(Long nodeId)
Returns a [parentnode_ID] token for the given node ID
String
formatUserInfo(CSMember user)
Returns a [user_ID] token for the given CSMember
String
formatLink(String href, String text, String title, String alt)
Registers and returns a [csurl_KEY] token for a clickable link. The title and alt parameters are optional

sendMessage parameters

All five sendMessage* variants accept the same parameters. Only recipients, subject, message, and shortMex are required; the rest are optional and default to null.

Parameter Type Description
recipients List<CSMember> List of users who will receive the notification
subject String Subject line for the notification
message String Main message body. Supports tokens such as [node_ID], [user_ID], [csurl_KEY]
shortMex String Short preview text shown in the notification badge
subjectDecoration String Controls the notification icon: [info] (default), [user], [process], or [node_NODEID]
aggregateKey String Used internally by the Notification Center. Not needed for aggregation — use fingerprint instead
expirationDays Integer Number of days until the notification expires and is removed
fingerprint String Key used to aggregate multiple notifications into a single grouped entry. Messages sharing the same fingerprint are collapsed together