Skip to main content

Script

1. Overview

The Script component (script) runs a custom code snippet (in the MVEL expression language) within the flow, allowing logic that the platform's ready-made components don't cover — specific calculations, date formatting, identifier generation, and more.

Use it when the needed logic is too simple to justify a dedicated component, but goes beyond what an Add Variable or Choice can express. Avoid overusing Script for complex business logic — that makes the flow harder to maintain for those unfamiliar with the MVEL language.

2. Prerequisites

Basic knowledge of the MVEL language (similar to Java) to write the expression.

3. Authentication and Connection

Not applicable — local processing.

4. Configuration / Supported Operations

The component has a single operation: run the configured code.

FieldRequiredTypeDescriptionExample
expressionYesText (MVEL code)Code to run. Inside it, the following are available: body (the message body, as an object if JSON), headers (the message headers), variables (variables defined by a previous Add Variable, if any), output (object used to set the result, with output.writeBody(...) and output.addHeader(key, value)), and func (ready-made utility functions, see below).A script that calculates a value and writes it to output

Utility functions available in func

FunctionDescription
func.getCurrentTimestamp() / func.getCurrentTimestamp(timeZone)Returns the current date/time.
func.getCurrentTimeMillis()Returns the current time in milliseconds.
func.formatDate(timestamp, pattern)Formats a date/time according to the given pattern.
func.addDays(timestamp, days)Adds days to a date.
func.base64Encode(text) / func.base64Decode(text)Encodes/decodes Base64.
func.md5(text) / func.sha256(text)Generates an MD5/SHA-256 hash of a text.
func.generateUuid()Generates a unique identifier (UUID).
func.fromStorage(scope, key)Reads a value stored in Local Storage.
func.fromEnv(key)Reads a platform environment variable.

5. Practical Examples

Simple example: generate a unique identifier and add it to the message body.

Input:

{
"order": { "customer": "Maria Silva" }
}

Component configuration:

{
"componentName": "script",
"configurations": {
"expression": "output.writeBody([\"order\": body.order, \"protocol\": func.generateUuid()]);"
}
}

Response:

{
"order": { "customer": "Maria Silva" },
"protocol": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}

Advanced example: calculate the due date (30 days from today) and add a custom header to the response.

Component configuration:

{
"componentName": "script",
"configurations": {
"expression": "dueDate = func.addDays(func.getCurrentTimeMillis(), 30); output.addHeader('x-processed-by', 'script'); output.writeBody([\"order\": body.order, \"dueDate\": func.formatDate(dueDate, 'MM/dd/yyyy')]);"
}
}

Response:

{
"order": { "customer": "Maria Silva" },
"dueDate": "08/19/2026"
}

6. Common Errors and Troubleshooting

Error / SymptomLikely CauseHow to Fix
Error starting the flow, related to script compilationThe expression's MVEL syntax is incorrect.Review the code's syntax.
Runtime error, with the original MVEL messageThe code tried to access a nonexistent field in body, or an invalid operation.Review the fields used and test the logic with sample data.
func functions return an empty stringA parameter passed to the function is invalid (e.g., a date in the wrong format).Review the parameters passed to the utility function used.