Skip to main content

Version: 19.05 (EOL)

Groovy Guide

Groovy is a powerful scripting language which runs on the Java Virtual Machine. This gives you access to all the facilities provided by Journey Manager and Java, while providing a scripting language without the steep learning curve of Java.

You can think of Groovy as JavaScript for the server. It is a dynamic language, there are no compile and deploy steps. Just write it and run it.

The Temenos Journey platform provides customized Groovy runtime with security constraints for running in an application server context. For Groovy version information, see Groovy Lang in Journey Manager 3rd Party Libraries.

Simple Example

The simple hello world example below defines a variable called name, and assigns it the value 'World'. Then on the next line this variable $name is included in the text output to the screen using the println function.

def name = 'World' 
println "Hello $name!"

And as expected the result is:

Hello World!

Learning Groovy

If you're familiar with programming in a modern language then you should find Groovy easy to learn. It has a C-like syntax in common with C#, JavaScript, and Java, and has scripting features so you don't have to write lots of code.

This Groovy guide provides a quick introduction to the language to give you the skills you need to start developing Groovy Service scripts.

As you are working through the examples in this guide, you can use the Groovy Script Console under the System menu in your Journey Manager environment. This provides a playground where you can try out examples and prototype Groovy scripts.

Groovy Script Console

Script Type Checking

Where possible configure your services to use the Groovy Script Type Checked option. When using the option the script will be parsed before executing to see whether there are any script type errors. These compilation style errors messages are generally more informative that the standard Groovy dynamic execution errors.

The following example has the Script Type Checked option, and displays the cause of the error and where (line and column number) it occurs.

Groovy Script Type Checked

Without type checking, the error is reported as shown below. Note that the error doesn't include the line number so you would need to search you script to find the corresponding missing method.

Thu Apr 17 11:41:54 EST 2014
2014-04-17
groovy.lang.MissingMethodException: No signature of method: java.util.Date.formatter() is applicable for argument types: (java.lang.String) values: [yyyy-MM-dd'T'HH:mm:ss]
Possible solutions: format(java.lang.String), format(java.lang.String, java.util.TimeZone)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script1.run(Script1.groovy:9)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:556)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:527)
note

When using the Script Type Checked option, you may need to write your scripts in a more statically declared Java-like fashion to enable the Groovy runtime to figure out what you are trying to achieve.

To configure Script Type Checked on your service, configure the service definitions groovyTypeChecked Service Parameter to be true. By default, this option is not set to ensure backward compatiblity with older scripts.

Groovy Script Type Checked Configuration

Next Steps

If you want to learn more about Groovy once you have completed this guide, see Groovy Language Documentation.