Script Body Guide (Groovy Java)
This page explains how to write the Script Body for an Alert Script. The script runs server-side and synchronously when the trigger event fires (Create / Update / Delete).
The script acts as a boolean filter:
Return
true→ the event is significant and an alert should be generatedReturn
false→ suppress the alert for this event
1) Script Body rules (must-follow)
Groovy only
The Script Body is the inside of a method ✅ Write statements directly ❌ Do not add a class or method signature
Always return a boolean on every path
Prefer early
return falsefor readability and safety
2) Runtime variables (available without declaration)
These are injected into the script context automatically:
Core context
dlpObject(Object) Current state of the object that triggered the event.oldDlpObject(Object) Previous state of the object only for UPDATE events. Oftennullon INSERT, and may not match expected type.wsUser(User) The user/system account that performed the action. Useful for role-based suppression.
Message output
mapResultsForMessage(Map<String, String>) Placeholder map for template-based message text. Typical keys are"?1","?2"etc.mapMessageFromServer(Map<String, String>) Full message override. Use key"MSG"to provide the message text.
3) Recommended structure (copy-paste mental model)
A clean script usually follows this flow:
Imports (only what you use)
Type check + cast
dlpObject(and optionallyoldDlpObject)Guard clauses for nulls / wrong event shape
Business logic (status checks, threshold checks, role checks, etc.)
Populate message values (template placeholders or full message)
return true
4) Type check + casting (avoid ClassCastException)
dlpObject and oldDlpObject are generic Object, so type-check first.
For old object (updates only):
5) Null-Safety: Patterns and Best Practices
Assume linked objects can be null (headers, vessel, statuses, etc.). Use:
Guard clauses
Groovy safe navigation
?.Null coalescing
?:
6) Field access and status comparisons
Linked object navigation
Status fields
Compare status codes, not the status object:
7) Update/change detection (current vs old)
If your trigger is UPDATE and you only want alerts on change:
Step-by-step pattern
Null-safe comparisons
Avoid calling .equals() on potentially null values.
Numeric thresholds (example)
8) Message building modes (CRITICAL – prevents misconfiguration)
There are two valid combinations between the Script Body and Message Configuration.
Mode A — Build message in script = true
Use this when the Script Body produces the full message text.Requirements
Build message in script = trueScript must set:
mapMessageFromServer["MSG"]
Mode B — Build message in script = false
Use this when the server builds the message using a template string (messageTxt) and placeholder map.
Requirements
Build message in script = falsemessageTxtmust be provided (example:"Hello ?1")Script sets:
mapResultsForMessage["?1"] = "World"
Example configuration:
messageTxt = "Hello ?1"
Script:
The broken combo
Don’t do this:
mapResultsForMessage+Build message in script = true
Reason: Build message in script = true expects "MSG" in mapMessageFromServer.
9) Guidance for generators / validation logic (recommended)
When auto-generating alert script configs, set Build message in script using this rule:
If Script Body contains
mapMessageFromServer→ set trueElse if Script Body contains
mapResultsForMessageANDmessageTxtis set → set falseElse → fail validation or require the missing pieces (recommended)
This prevents “alerts firing with empty messages” situations.
10) Optional: fetching related data (advanced)
Sometimes the needed data is not reachable from dlpObject (link not loaded / not present). You can query the database using:
Method details can vary by version and are not fully documented. Use known examples as reference and test carefully.
11) Troubleshooting
Logging
Print debug information to application logs:
Return-path sanity
If alerts don’t fire:
confirm type-check isn’t rejecting
confirm
oldDlpObjectisn’t null when you expect update logicconfirm message building is valid
12) Full example (safe, readable, and template-based)
Config:
Build message in script = falsemessageTxt = "Voyage ?1 PNL changed to ?2"
Script:
Was this helpful?