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
- Martini Designer installed and running on your system
- Basic knowledge of any of Martini's supported programming languages
- Understanding of workflow properties and data flow
- Create a Martini Package
- Create a Workflow
Getting Started
- Navigate to your Martini Package and open your workflow
- Click the Add Node button in the toolbar on the top left of the editor
- Select Script from the available node types
- Drag the Script Node to your desired position in the workflow
- Connect it to other nodes using workflow edges
- Click the expand icon on your Script Node to open the Script Panel
-
Select your script language:
- Click the on the top right of the Script Panel
- Choose your preferred language (see Supported Languages)
-
Click Show Available Properties in the editor to view all workflow properties that can be used in your script
- Click any property name to automatically insert it into the editor
- 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
orderAmountandtaxRate, and an output propertytotalAmount. 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 | |
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:
- Property Access: The script automatically has access to all workflow properties defined in the workflow
- Execution Context: Code runs within Martini's secure execution environment with access to Java standard libraries
- Property Assignment: You can create new workflow properties or modify existing ones by direct assignment
- Error Handling: Runtime exceptions are caught and reported with detailed stack traces including script line numbers
- 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
- Groovy Documentation
- Workflow Nodes
- Map Node
- Workflow Properties and Data Flow
- Create a Martini Package
- Create a Workflow
- Workflow Edges
- Workflow Input & Output
- Workflow Designer
- Community Q&A: Martini Community
Have a Question? Post or search it here.