The invoke step is used to invoke other Gloop services, Flux services, and compatible Java and Groovy services1 in Gloop. It borrows the Mapper view from the map step, meaning you can also set variable values, declare new variables, or unload them in invoke steps. This makes Gloop infinitely more powerful, because if there's anything you can't do in Gloop, you can do it in Flux, Java, or Groovy! This also means that you can reuse existing services by wrapping them in invoke steps in Gloop services to make managing your services and APIs easier.
The Mapper view for invoke steps has two mappers inside it. One is for mapping input variables (on the left hand side) for the service/code it will invoke, and the other is for mapping output variables from the invoked service (on the right hand side).
Mapper in Invoke Steps
When an invoke step is selected in the Gloop service editor, the Mapper view in Coder will show all of the available input and output variables for the service to be invoked, as well as the variables available in the current scope of the service. This is where you map variable values from the current scope of the service to the service to be invoked and add set expressions to the inputs of the service to be invoked. After the service has been invoked, Gloop will then map and set all of the variables on the Output side of the Mapper view.
For example, the mapper screenshot below:
... is the same as the following Groovy code:
1 2 3 4 5 6
// Invoke some code. GloopModel output = TrackerMethods.searchTracker(trackerQuery, externalIds, documentTypeId, 'Error', 'CustomerX', 'Togo', 'now', null, null, null, null, null, 100, 2) // Declare the searchResult variable and map (set) it. GloopModel searchResult = output.searchResult // Declare the numberOfResults variable and map (set) it. int numberOfResults = output.searchResult.numFound
Annotating code to make it Gloop-friendly
Gloop has a nifty set of annotations that are used to decorate Groovy and Java code with metadata to make your code look even better in the Gloop UI (and easier to use whilst writing Gloop services).
Adding Invoke Steps
There are two ways to add an invoke step to your Gloop service:
- Drag and drop the service you want to invoke from the Coder Navigator view.
- Use Coder's auto-complete feature (activated by pressing in the Gloop service editor), then start typing in the name of the service you want to invoke. Once you find your selection in the list, click on it or use the cursor keys to highlight it and then press .
Below is a GIF showing both ways:
Map and declare in one go!
If you would like to map the output of an invoke step to a new variable, simply drag the variable to the output tree, whilst holding ⌥ in macOS (or Ctrl in Windows and Linux). This will declare the variable and map it for you in one step!
For a Java or Groovy service to be compatible, the method needs to be