Skip to content

Martini Workflows Script Node

Overview

The Script Node is a powerful workflow component that executes custom code directly within your workflows. With full access to all workflow properties, it provides complete control over complex logic, data transformations, and calculations that can't be achieved with the other low-code workflow nodes.

When to Use This

Use this when you need to:

  • Implement complex mathematical calculations or algorithms
  • Perform custom data transformations beyond standard mapping
  • Access external APIs programmatically

Prerequisites

Getting Started

  1. Navigate to your Martini Package and open your workflow
  2. Click the Add Node button in the toolbar on the top left of the editor
  3. Select Script from the available node types
  4. Drag the Script Node to your desired position in the workflow
  5. Connect it to other nodes using workflow edges
  6. Click the expand icon on your Script Node to open the Script Panel
  7. Select your script language:

    • Click the on the top right of the Script Panel
    • Choose your preferred language (see Supported Languages)
  8. Click Show Available Properties in the editor to view all workflow properties that can be used in your script

  9. Click any property name to automatically insert it into the editor
  10. Write your code in the Script Panel Editor

For example, calculating a customer's total order value with tax (Groovy):

Required workflow properties: For this script to work, your workflow must have input properties named orderAmount and taxRate, and an output property totalAmount. See Workflow Input & Output to learn how to declare and manage input and output properties.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Groovy example
// Calculate total amount including tax
def baseAmount = orderAmount ?: 0
def rate = taxRate ?: 0.08 // Default 8% tax rate

// Apply tax calculation
totalAmount = baseAmount * (1 + rate)

// Round to 2 decimal places for currency
totalAmount = Math.round(totalAmount * 100) / 100

// Log the calculation for debugging
println "Order: $baseAmount, Tax Rate: ${rate * 100}%, Total: $totalAmount"

Expected result: The workflow property totalAmount contains the order amount plus calculated tax, rounded to two decimal places.

How It Works

The Script Node allows you to write and execute custom code directly within your workflow:

  1. Property Access: The script automatically has access to all workflow properties defined in the workflow
  2. Execution Context: Code runs within Martini's secure execution environment with access to Java standard libraries
  3. Property Assignment: You can create new workflow properties or modify existing ones by direct assignment
  4. Error Handling: Runtime exceptions are caught and reported with detailed stack traces including script line numbers
  5. Integration: The node seamlessly integrates with other workflow nodes, passing data through the workflow pipeline

The Script Editor provides syntax highlighting and auto-completion to help you write reliable code.

Supported Languages

Martini supports multiple scripting languages for Script Nodes. The available options are:

  • Groovy (default)
  • Batch
  • Python (option appears if installed)
  • JavaScript (option appears if installed)

Why It Matters

Script Nodes bridge the gap between simple workflow operations and complex custom logic that other nodes can't handle:

vs. Map Nodes: Map Nodes are best for simple data changes and short expressions. If your logic is too complex for a single set expression in a Map Node—like multi-step calculations or longer code—use a Script Node instead.

vs. Invoke Workflow/Invoke Service Nodes: Instead of creating separate workflows or services for one-off calculations, Script Nodes let you write custom logic directly in your workflow, keeping related code together.

vs. Invoke Function Nodes: Martini provides built-in functions for common tasks like parsing data, processing values, or using external libraries—these are quick and easy to use for simple logic. However, if your workflow needs more advanced or custom logic that can't be handled by the available functions, or if your requirements don't fit the built-in options, use a Script Node. Script Nodes let you write your own code directly, giving you full flexibility to solve complex problems within your workflow.

vs. other Workflow Nodes: When other workflow nodes can't express your business logic, Script Nodes provide the full power of supported programming languages within your workflow context.

This gives you the flexibility to implement exactly what your workflow requires, without leaving the Martini environment or over-engineering simple custom logic into separate services.

Troubleshooting

Problem Detection Cause Fix
Property Not Found Runtime exception with MissingPropertyException and "No such property" message Property doesn't exist in workflow or unavailable to the script node Verify property names and ensure the property was declared/added before the script node

Helpful Resources