Defining Utility Code in a Global Function

Global functions are useful for code that multiple objects want to share. To call a global function, preface the function name with the adf.util. prefix.

When defining a function, you specify a return value and can optionally specify one or more typed parameters that the caller will be required to pass in when invoked.

The most common types for function return values and parameters are the following:

  • String: a text value

  • Boolean: a logical true or false value

  • Long: an integer value in the range of ±263-1

  • BigInteger: a integer of arbitrary precision

  • Double: a floating-point decimal value in the range of ±1.79769313486231570 x 10308

  • BigDecimal: a decimal number of arbitrary precision

  • Date: a date value with optional time component

  • List: an ordered collection of objects

  • Map: an unordered collection of name/value pairs

  • Object: any object

In addition, a function can define a void return type which indicates that it returns no value.

Tip: A global function has no current object context. To write global functions that work on a particular object, refer to Passing the Current Object to a Global Function.

For example, you could create the following two global functions to define standard helper routines to log the start of a block of groovy script and to log a diagnostic message. Examples later in this document will make use of them.

  • Function Name: logStart

  • Return Type: void

  • Parameters: scriptName String

Function Definition

// Log the name of the script
println("[In: ${scriptName}]")
  • Function Name: log

  • Return Type: void

  • Parameters: message String

Function Definition

// Log the message, could add other info
println(message)