Skip to content

Martini Services Script Step

Overview

A script step is a segment of code within a service step. It has full access to the variables available in the service context. When your service requires custom logic not achievable with standard steps, consider:

  • Writing a standalone, reusable Groovy class for integration into services.
  • Creating a new reusable script service.
  • Adding a single-use script step directly into your service.

Example

Consider a script step in Groovy to compute Fibonacci numbers. The script defines a function for this calculation, and its output is assigned to a variable.

Key points: - A function is declared at the start of the script and called later in the script. - The result is stored in a specific variable.

The script step editor offers a user experience akin to set expression editors.

Best Practices

It is advisable to consult design guidelines for writing maintainable and reusable code in this context.

Managing Script Steps in Editor

To view or hide script step content in the service editor, use the "Show Script Lines" option in the toolbar's Filter menu.

Error Handling

Errors in script steps, whether from syntax issues or exceptions, result in a specific error output. This includes the line number in the script where the error occurred. For example:

1
2
io.toro.exception.Exception: groovy.lang.MissingPropertyException: No such property: error for class: Script1
    at ExampleScript.Script(ExampleScript.service:2)[7]

This output details the service and specific line number of the error:

1
2
3
at ExampleScrip.Script(ExampleScript.service:2)[7]
-----------------------------------------------------------------
                      |     Service   | Script Line Number

Runtime exceptions in script steps, including syntax errors, are caught like any other exceptions by parent block steps with a catch clause.