Activities

Script Task

A task executed by the process engine itself, running a script defined in the model (e.g. JavaScript, Groovy). When the script finishes, the task completes. Marked with a script/scroll icon.

The Script Task (Script Task) embeds a small piece of executable logic directly in the process: the modeler defines the script language and the script body, and the engine interprets it when the token arrives.

It shines for glue logic — computing a value, transforming data between steps, setting process variables — where spinning up an external service would be overkill. The flip side: scripts hide logic inside the diagram, so heavy use hurts maintainability. Keep scripts short; promote anything substantial to a Service Task or a Business Rule Task.

When to use and avoid

When to use

  • For small computations: calculate a score, derive a due date, format a reference number.

  • For data transformation between activities (mapping fields, aggregating values).

  • When calling an external service would add latency and operational cost for trivial logic.

When NOT to use

  • For integration with external systems — that is a Service Task.

  • For business decisions that change often (pricing rules, eligibility) — a Business Rule Task keeps them in a decision table that business people can maintain.

  • For long-running or resource-heavy logic — scripts run inside the engine and can degrade it.

Business example

Calculating a risk score in a loan application

Diagrama BPMN: Calculating a risk score in a loan application
Calculating a risk score in a loan application

Open this example in the HEFLO process editor and explore the diagram from the inside.

Open in the HEFLO editor →

Step by step

  1. The process starts when a loan application is received.
  2. The Script Task “Calculate risk score” (highlighted) runs inside the engine: it combines income, history and amount into a numeric score — no external call, no human.
  3. The Exclusive Gateway routes by the result: high scores go to Auto-approve; the rest go to Manual review.
  4. Both paths end the process.

The script produces the data that the very next gateway consumes — the most idiomatic use of a script task.

Differences

Difference between a Script Task and a Service Task

The Script Task runs logic *inside* the engine, written in the model. The Service Task delegates to something *outside* — an API, a service, another system. Internal glue logic → Script; integration → Service.

Difference between a Script Task and a Business Rule Task

Both compute a result automatically, but the Business Rule Task externalizes the decision into a rules engine/decision table (typically DMN) that business users maintain, while the Script Task buries the logic in code inside the model. If the rules change with the business, prefer the Business Rule Task.

FAQ

Which script languages can I use?

Whatever your engine supports — the BPMN attribute scriptFormat declares the language. JavaScript and Groovy are the most common in practice.

Why keep scripts short?

Scripts are invisible to diagram readers and hard to test in isolation. Long scripts turn the model into a code repository without version control ergonomics — move substantial logic to services.

Related elements