• Platform
    • Manager
    • Maestro
    • Exchange
    • Workspaces
    • Analytics
    • Springboard
    • API
Transact Services Guide (TSG)

Transact Services Guide (TSG)

  • Getting Started
  • Groovy Guide
  • Service Development
  • Groovy Services API
  • REST API

›Groovy Guide

Getting Started

  • Introduction

Groovy Guide

  • Groovy Guide
  • Groovy Declarations
  • Control Statements

Service Development

  • Service Development
  • Transaction Processing Sequence
  • Service Logging
  • Remote Service Calls
  • Fluent Security Configuration
  • Third-party Libraries

Groovy Services API

  • Groovy Services API
  • Fluent Function
  • Delivery Function
  • Form Version Selector
  • Form Security Filter
  • Form Prefill
  • Tracking Number
  • Form Dynamic Data
  • Submission Preprocessor
  • Receipt Number
  • Form Saved Processor
  • Submission Data Validator
  • Submission Completed Processor
  • Render Receipt Service
  • Delivery Process
  • Task Expiry Process
  • Email Service
  • Job Action
  • Scheduled Service
  • Groovy Service
  • SSO Revalidation
  • SSO Get Authentication Token
  • SSO Authentication OK Response
  • SSO Authentication Provider
  • Transaction History Publisher
  • Virus Scan

REST API

  • REST API
  • REST Application Package API
  • REST Delivery API
  • REST Form Groups API
  • REST Groovy Service Invoke v2
  • REST Service Definitions API
  • REST Tasks API
  • REST TestCenter API
  • REST TPac API
  • REST Transactions API
  • REST Transaction History API

Workspaces API

  • Workspaces API
  • Filters
  • Sort
  • Workspaces Category API
  • Workspaces Current User API
  • Workspaces Extract Name API
  • Workspaces Form API
  • Workspaces Group API
  • Workspaces Job API
  • Workspaces Org API
  • Workspaces Property Name API
  • Workspaces Space API
  • Workspaces Txn API
  • Workspaces User API

Control Statements

Groovy control statements are modeled on C-style statements. You can do a lot with very little.

Branching Logic

Groovy support if/else statements, switch statements and the ternary operator. Generally you should be able to get by with using if/else statements.

If Else Statements

The if else statements are pretty straightforward.

def seats = 2

if (seats == 0) {
  println 'There are no seats'

} else if (seats == 1) {
  println 'There is one seat'

} else if (seats == 2) {
  println 'There are two seats'
  
} else {
  println 'There are more than two seats, if you think positively'
  
}

which will print out the message

There are two seats

Compact If Else plus Assignment

There is also the ternary operator, which provides an if else statement combined with a variable assignment.

def seats = 1
def msg = (seats == 2) ? "There are two seats left" : "Sorry we don't have 2 seats left"
println msg

This script will print out the message

Sorry we don't have 2 seats left

Looping

For Statement

Using the for statement you can loop over a range of numbers, lists and maps.

Number Iteration

In a for statement you can specify the starting index, the iteration test and increment operation.

def items = [ "banana", "apple", "orange", "mango", "grapes", "kiwi fruit" ] 

// Start at index 0, only loop while the index is less than the length of the list, 
// and increment the index by one for each iteration
for (int i = 0; i < items.size(); i++) {
   println i + ". " + items[i]
}

This script will print out the message

0. banana
1. apple
2. orange
3. mango
4. grapes
5. kiwi fruit

List Iteration

When looping through a list you can use the for each item in items syntax

def items = [ "banana", "apple", "orange", "mango", "grapes", "kiwi fruit" ] 

// For each item in the list of items
for (item in items) {
   println item
}

This script will print out the message

banana
apple
orange
mango
grapes
kiwi fruit

Map Iteration

Maps are special in that you can iterate through them a number of ways.

def car = [ "seats" : 4, doors: 2, "color" : "red", "year" : 2011 ]

// For each map entry
for (entry in car) {
   println entry.key + ": " + entry.value 
}
def car = [ "seats" : 4, doors: 2, "color" : "red", "year" : 2011 ]

// For each map entry key (name)
for (key in car.keySet()) {
   println key + ": " + car[key] 
}
def car = [ "seats" : 4, doors: 2, "color" : "red", "year" : 2011 ]

// For each value in the map
for (value in car.values()) {
   println value
}

Please note to find something in a map you can generally lookup the value using the key.

Returning Values

In Groovy script you can return an object to the calling code using the return statement.

def car = [ "seats" : 4, doors: 2, "color" : "red", "year" : 2011 ]

if (car["doors"] == 2) {
   return "We don't insure sports cars"
}

println 'Continue processing'

// Continue processing
..

Catching Errors

If you need to handle errors and continue processing you can use the try / catch statement.

def textValue = "z123"

def intValue
try {
   intValue = Integer.parseInt(textValue)

} catch (Exception e) {
   println e
   intValue = -1
}

println "Integer value: " + intValue
← Groovy DeclarationsService Development →
  • Branching Logic
  • Looping
  • Returning Values
  • Catching Errors

Terms & Conditions

Privacy Policy

Cookie Policy

Copyright © 2003-2022 Temenos Headquarters SA