Skip to Content

Script Task

A script task executes an inline script synchronously using the Rhai  scripting engine.

<scriptTask id="calcTotal" name="Calculate Total" scriptFormat="rhai"> <script> variables.total = variables.price * variables.quantity; </script> </scriptTask>

Execution behavior

The script runs before the engine advances past the element and completes immediately — no waiting state is entered.

Inside the script the variables map is available for both reading and writing:

let price = variables["price"]; variables["discount"] = if price > 100.0 { 0.1 } else { 0.0 }; variables["total"] = price * (1.0 - variables["discount"]);

All writes to variables are persisted to the instance variable scope after the script completes.

resultVariable

Set activiti:resultVariable to capture the script’s return value into a named variable:

<scriptTask id="greet" scriptFormat="rhai" activiti:resultVariable="greeting"> <script>"Hello, " + variables["name"]</script> </scriptTask>

The last evaluated expression in the script is stored under the specified variable name.

Error handling

If the script throws a runtime error the instance transitions to Failed. Attach a boundary error event to the script task to catch and redirect on failure.

Last updated on