Skip to main content

Backend Scripting with SpEL

SpEL (Spring Expression Language) is the scripting engine used in tSM to power backend automation, workflow execution, and process logic. It allows you to reference entities, calculate values, enforce conditions, and interact with data programmatically — directly from inside BPMN processes, service tasks, SLA rules, and API hooks.

SpEL scripts run on the server, making them ideal for use cases where security, consistency, or background execution is required.

Where is SpEL Used?

AreaTypical Usage Examples
Process Engine (BPMN)Conditions, timers, expressions in gateways/tasks
SLA / KPI RulesDynamic target times, escalation logic
API HooksPre/post-processing of requests and payloads
Custom Script TasksInline backend logic inside automation workflows
Event TriggersRun code on entity lifecycle events (e.g., ticket created)

SpEL Syntax Basics

  • Similar to Java/Kotlin-style expressions
  • Supports logic, math, object navigation, and custom helpers
  • References start with #, e.g. #ticket, #orderTotal, #currentUser()
#if(#ticket.priority == 'High').then(#escalate = true).else(#escalate = false)

Common Variables

VariableDescription
#ticket, #orderThe current entity context
#currentUser()Active user executing the logic
#now()Current timestamp
#addDays(date, 2)Utility to manipulate time values

Gateway Condition Example

#order.totalAmount > 1000

Used in an exclusive gateway to route to "Manager Approval" if total exceeds 1000.

SLA Escalation Example

#now().plusHours(48)

Used to set a dynamic SLA deadline 48 hours from now.

API Hook Transformation

In an API pre-processing script:

#requestBody.customerName = #requestBody.customerName.toUpperCase()

Ensures incoming names are uppercase before saving.

Process Task – Script with Variable Set

#if(#ticket.category == 'Urgent') {
  #ticket.priority = 'High'
}

Used in a script task to auto-update priority based on category.

Helpers and Utilities

CategoryFunctions & Helpers
Time#now(), #addDays(), #diffInMinutes()
Math#sum(), #round(), #abs()
Logic#if(condition).then(...).else(...)
Collections#list(...), #contains(...)
JSON/Map#get(), #set(), #toJson()

Over 1500 methods are available — check the built-in script editor in tSM for autocompletion and docs.

Debugging SpEL

  1. Open an entity (e.g., order, ticket)
  2. Click ⋯ → SpEL Console
  3. Run SpEL scripts in live context with suggestions
  4. View outputs, test logic, and iterate safely

Best Practices

  • Always validate expressions in the SpEL Console
  • Use #if(...).then(...).else(...) for clean conditional logic
  • Avoid side effects in conditions — keep logic pure
  • Reuse helper functions to avoid duplication
  • Document complex logic in comments where supported

JEXL vs. SpEL – Quick Comparison

FeatureJEXL (Frontend)SpEL (Backend)
Execution ScopeIn browser, at runtimeOn server, in processes
Access to $contextYesNo – uses # variables
Use CasesUI logic, formsWorkflow, automation, APIs
Multi-line Support❌ (single expression)
DebuggingJEXL Console (form-based)SpEL Console (entity-based)