Contact Free trial Login

Scripting Module Reference - Mule 4

Support Category: Select

Scripting Module v2.0

The Scripting Module executes custom logic written in a scripting language.

Configurations


Config

Default configuration

Parameters

Name Type Description Default Value Required

Name

String

The name for this configuration. Connectors reference the configuration with this name.

x

Operations

Execute

<scripting:execute>

Run a script with provided code, according to the engine and passing parameters. The script provides many binding variables to work with:

Name Type Description

payload

Object

The payload of the message processed.

dataType

Data type of the message payload.

correlationId

String

The correlationId of the message processed.

attributes

Map<String, Object>

Attributes of the Mule message processed.

vars

Map<String, Object>

The variables set on the current Mule event processed.

message

The message processed.

error

Error associated with the Mule message processed.

authentication

Information about the authentication.

flow

String

The name of the current flow.

log

Logger

Logger object that logs to the app’s log file, MULE_HOME/logs/<app-name>.log

result

Object

Variable representing the result of the script execution.

registry

org.mule.runtime.api.artifact.Registry

Use the registry object to access any other service within the Mule API.

If the code doesn’t produce an implicit result, you have to set the result variable value explicitly with the execution result. The payload is set with this value unless you configure a target variable as described in Scripting Module documentation.

Parameters

Name Type Description Default Value Required

Code

String

The script source code to execute

x

Engine

String

Name of the scripting engine for running this script

x

Parameters

Map<String, Object>

Variables provided to the script as bindings

Target Variable

String

The name of a variable on which to place the operation’s output

Target Value

String

An expression to evaluate against the operation’s output. The outcome of that expression will be stored in the target variable.

#[payload]

You must export the classes used with the Scripting Module, otherwise, the execution fails with a SCRIPTING:COMPILATION error. See how to export resources.

Throws

  • SCRIPTING:COMPILATION

  • SCRIPTING:UNKNOWN_ENGINE

  • SCRIPTING:EXECUTION