Groovy Console

   Journey Manager (JM) Previously known as Transact Manager (TM).  |    Form Builder Platform Developer |  v17.10 This feature was introduced in v17.10.

Manager comes with the GroovyGroovy is a powerful scripting language which runs on the Java Virtual Machine. Across theJourney platform, Groovy is used to create services in Manager. These services are primarily used to create plug-in style systems that interact with Manager. console enabling developers to rapidly develop and test Groovy scripts. Groovy console has an access to all services and libraries, so it can simulate the behaviors of any Groovy service.

To test a script in the Groovy console:

  1. Select Services > Groovy Console.
  2. Select the Groovy Script tab to type a new or copy and paste an existing Groovy script here. You can type only a part of a script as well, which is shown above.
  3. Select the Secure Fluent API Only checkbox to enforces the use of Transact Fluent API in this Groovy script. It is selected by default. Clear this checkbox if you want to test the Groovy script that uses Transact Core API.
  4. Note

    At installation time, the system wide build property groovy.secure.api defines whether the Secure Fluent API Only service parameter is editable or available.

  5. Select the Commit DB Changes checkbox to define whether any changes made by this script to the database has to be committed or rolled back. This is handy when you want to test a Groovy script that writes to the DB, but you don't want to delete these test records from the DB manually. It is not selected by default.
  6. Enter a timeout in the Execution Timeout (sec) field to specify the Groovy script execution timeout in seconds, after which a timeout exception will be thrown. The default is 60 sec.
  7. Click Execute Script to run it. The script output or an error message is shown in the Execution Output window.
  8. Click Syntax Check to validate the Groovy script, which checks the script spelling, as shown below.
    
    [Static type checking] - Cannot find matching method Script1#printl(groovy.lang.GString). Please check if the declared type is correct and if the method exists.
    	@ line 2, column 1.
    	printl "Hello world, $it"
    	^
     
    	1 error
    
  9. Click Clear Output to clear the Execution Output text field.
  10. Click Clear Script to clear the Groovy Script text field.
  11. click Save Script to save the script.
  12. Select the Service Parameters tab to create and edit existing Groovy script parameters.
  13. Click New to create a new parameter.
  14. Type in a name and a value.
  15. Click Save to update the changes. Now you can use companyName parameter in the Groovy script, as shown below.
    
    def name = serviceParameters.companyName
    (0..9).each {
    	println "Hello $name, $it"
    }		
    

You can use more complex Groovy code snippets including imports, as shown below:


import com.avoka.tm.query.*
import com.avoka.tm.vo.*

String trackingCode = "LHC5DD"
String txnPropertyName = "Monty"

Txn txn = new TxnQuery()
	.setTrackingCode(trackingCode)
	.firstValue()

// PropertyQuery() to access the Monty property value
String txnPropertyValue = new PropertyQuery()
	.setName(txnPropertyName)
	.setTxn(txn)
	.getValue()

// expected result: txnPropertyValue = Python
println "txnPropertyValue = ${txnPropertyValue}"

Next, learn about Groovy service log.