Skip to main content
Version: 2.3

Frontend Scripting with JEXL

JEXL (JavaScript Expression Language) enables dynamic behavior in tSM forms — such as showing/hiding fields, calculating default values, or enforcing validation rules — all without backend code.

It runs in the browser at runtime, and is used throughout forms and pages via the Form Designer.

What is JEXL Used For?​

Use CaseExample
Conditional visibilityHide a field if the user selects "B2C"
Default valuesSet date field to "today + 1"
Custom validationEnsure value falls within limits based on another field
Data transformationJoin two strings or check if an item exists in a list
Context-based filteringShow only orders for the current customer

Where JEXL Can Be Used​

You’ll see JEXL-enabled fields in the Form Designer with a toggle icon:

  • hidden, readonly, disabled
  • default value
  • validationMessages
  • config fields
  • Listing filters

Once toggled, you can insert single-line expressions in JEXL.

JEXL Syntax Basics​

  • Only single-expression scripts (no multiline code)
  • Uses JS-style operators (+, ==, &&, ||, !)
  • Works with context variables and built-in functions
  • Evaluates to a value or true/false for boolean logic

Context Variables​

VariableDescription
$context.formThe current form being edited/created
$context.entityThe current entity (on detail pages)
$context.userCurrent user info (e.g., role, name)

Custom fields are always under .chars (e.g. $context.form.chars.priority)

Examples​

1. Hide a Field When Segment is B2C​

$context.form.customerSegment == 'B2C'

Used in config.hidden.

2. Set Default Date to Tomorrow​

addTime($context.form.orderDate, 1, 'days')

Used in default for a date field.

3. Validate VIP Discount Range​

($context.form.clientStatus == 'VIP') && 
($context.form.discountRate < 10 || $context.form.discountRate > 50)

Used in validationMessage → custom rule.

4. Check if List Contains a Value​

includes($context.form.selectedItems, 'apple')

5. Dynamic Label or Message​

"Hello " + $context.user.name

Used to personalize headers or tooltips.

Built-In Functions​

FunctionDescription
addTime(date, 1, 'days')Adds days/months/hours to a date
includes(array, value)Checks if value exists in list
sum(a, b, c)Adds numbers
isNullOrEmpty(value)Validates if value is missing or empty
dateFormat(date, 'yyyy-MM-dd')Formats date string output

A full list of functions is documented in the JEXL Function Reference

JEXL Debug Console​

To test expressions in live forms:

  1. Enable the debug console in your user settings
  2. Open a form and click the JEXL debug icon
  3. Use $context to explore live values
  4. Test expressions with real-time feedback

Best Practices​

  • Expressions must be single-line: no if/else blocks

  • Use descriptive field names (priorityLevel > prLvl1)

  • Combine logic with &&, ||, ternary (? :) when needed

  • Always test conditionals in runtime

  • Handle null or empty cases explicitly (isNullOrEmpty)