Script steps
A script step in Gloop is a code snippet within a Gloop step. Script steps have complete access to the Gloop variables that are available in the service where the script step is inserted. If you have some logic that needs to be executed in your service which can't be provided with the included Gloop steps, you have a few choices:
- Write a standalone, reuseable Groovy class with methods which can be dropped into your services;
- Create a new standalone, reuseable Gloop script service, or;
- Add a single-use script step into your service
The example above shows a simple script step (written in Groovy) with a function used to calculate Fibonacci
numbers count
times. In the screenshot, count
is 20
. Also from the screenshot, you can see the following:
- On line
1
of the script step a new function is declared, which is invoked from line5
and8
. - On line
8
, the output of the function is being set to a Gloop variable calledfibonacciSeries
.
The editor for script steps is very similar to the editor used for set expressions.
TORO recommends reading design guidelines to help you write more maintainable, reusable code in Gloop.
Script steps in the service editor
To show or hide script step content in the editor, toggle or untoggle the "Show Script Lines" option from the toolbar's Filter menu.
Errors in Script steps
If your script step throws an exception (regardless of whether it was from a syntax error or not, or the language),
Gloop will produce a standard Gloop stacktrace, but with an extra suffix telling you the line number where the error
occurred in your script step. For example, given the error below, the script at line 2
of the NaughtyScript
service had an error at line 7
of the script itself:
1 2 |
|
Note the second line in the stacktrace, below, which also has some extra notes on the line underneath:
1 2 3 |
|
Here is a screenshot showing the script step:
Errors in script steps
Exceptions can be thrown at runtime if your script step has a syntax error. Like any other exception, they
will be caught by any parent block steps with a catch
.