Understanding ADF's Additional Built-in Groovy Functions

This section explains a number of additional helper functions you can use in your scripts. Some provide a simple example as well.

Use the Functions tab of the code editor palette to insert any of the built-in functions into your script.

Built-in Date Functions

Function

Description

today()

Returns: the current date, with no time

Return Type: Date

now()

The current date and time

Return Type: Timestamp

date( year , month , day )

Returns: a date, given the year, month, and day

Return Type: Date

Parameters:

  • year - a positive integer

  • month - a positive integer between 1 and 12

  • day - a positive integer between 1 and 31

Example: to return a date for February 8th, 1998, use date(1998,2,8)

dateTime( y , m , d , hr , min , sec )

Returns: a timestamp, given the year, month, day, hour, minute, and second

Return Type: Timestamp

Parameters:

  • year - a positive integer

  • month - a positive integer between 1 and 12

  • day - a positive integer between 1 and 31

  • hour - a positive integer between 0 and 23

  • minute - a positive integer between 0 and 59

  • second - a positive integer between 0 and 59

Example: to return a timestamp for February 8th, 1998, at 23:42:01, use dateTime(1998,2,8,23,42,1)

year( date )

Returns: the year of a given date

Return Type: Integer

Parameters:

  • date - date

Example: if curDate represents April 19th, 1996, then year(curDate) returns 1996.

month( date )

Returns: the month of a given date

Return Type: Integer

Parameters:

  • date - a date

Example: if curDate represents April 12th, 1962, then month(curDate) returns 4.

day( date )

Returns: the day for a given date

Return Type: Integer

Parameters:

  • date - a date

Example: if curDate represents July 15th, 1968, then day(curDate) returns 15.

Built-in String Functions

Function

Description

contains( s1 , s2 )

Returns: true, if string s1 contains string s2, false otherwise

Return Type: boolean

Parameters:

  • s1 - a string to search in

  • s2 - a string to search for

Example: if twitterName holds the value @steve, then contains(twitterName,'@') returns true.

endsWith( s1 , s2 )

Returns: true, if string s1 ends with string s2, false otherwise

Return Type: boolean

Parameters:

  • s1 - a string to search in

  • s2 - a string to search for

For example, if twitterName holds the value @steve, then endsWith(twitterName,'@') returns false.

find( s1 , s2 )

Returns: the integer position of the first character in string s1 where string s2 is found, or zero (0) if the string is not found

Return Type: Integer

Parameters:

  • s1 - a string to search in

  • s2 - a string to search for

Example: if twitterName holds the value @steve, then find(twitterName,'@') returns 1 and find(twitterName,'ev') returns 4.

left( s , len )

Returns: the first len characters of the string s

Return Type: String

Parameters:

  • s - a string

  • len - an integer number of characters to return

Example: if postcode holds the value 94549-5114, then left(postcode,5) returns 94549.

length( s )

Returns: the length of string s

Return Type: Integer

Parameters:

  • s - a string

Example: if name holds the value Julian Croissant, then len(name) returns 16.

lowerCase( s )

Returns: the string s with any uppercase letters converted to lowercase

Return Type: String

Parameters:

  • s - a string

Example: if sku holds the value 12345-10-WHT-XS, then lowerCase(sku) returns 12345-10-wht-xs.

right( s , len )

Returns: the last len characters of the string s

Return Type: String

Parameters:

  • s - a string

  • len - an integer number of characters to return

Example: if sku holds the value 12345-10-WHT-XS, then right(sku,2) returns XS.

startsWith( s1 , s2 )

Returns: true, if string s1 starts with s2, false otherwise

Return Type: boolean

Parameters:

  • s1 - a string to search in

  • s2 - a string to search for

Example: if twitterName holds the value @steve, then startsWith(twitterName,'@') returns true.

substringBefore( s1 , s2 )

Returns: the substring of s1 that precedes the first occurrence of s2, otherwise an empty string

Return Type: String

Parameters:

  • s1 - a string to search in

  • s2 - a string to search for

Examples: if sku holds the value 12345-10-WHT-XS, then substringBefore(sku,'-') returns the value 12345, substringBefore(sku,'12345') returns an empty string, and substringBefore(sku,'16-BLK') also returns an empty string.

substringAfter( s1 , s2 )

Returns: the substring of s1 that follows the first occurrence of s2. otherwise an empty string

Return Type: String

Parameters:

  • s1 - a string to search in

  • s2 - a string to search for

Example: if sku holds the value 12345-10-WHT-XS, then substringAfter(sku,'-') returns the value 10-WHT-XS, substringAfter(sku,'WHT-') returns the value XS, substringAfter(sku,'XS') returns an empty string, and substringAfter(sku,'BLK') also returns an empty string.

upperCase( s )

Returns: the string s with any lowercase letters converted to uppercase

Return Type: String

Parameters:

  • s - a string

Example: if sku holds the value 12345-10-Wht-xs, then upperCase(sku) returns 12345-10-WHT-XS.

Other Built-in Functions

Function

Description

newView( objectAPIName )

Returns: a ViewObject reserved for programmatic use, or null if not available.

Return Type: ViewObject

Parameters:

  • objectAPIName - the object API name whose rows you want to find, create, update, or remove

Example: newView('TroubleTicket') returns a new view object instance you can use to find, create, update, or delete TroubleTicket rows.

key( list )

Returns: a multi-valued key object for use in the ViewObject's findByKey() method.

Return Type: Key

Parameters:

  • list - a list of values for a multi-field key

Example: if a standard object has a two-field key, use key([101,'SAMBA'])

key( val )

Returns: a key object for use in the ViewObject's findByKey() method.

Return Type: Key

Parameters:

  • val - a value to use as the key field

Example: if a standard object has a single-field key, as all custom objects do, use key(123456789)

nvl( o1 , o2 )

Returns: the object o1 if it is not null, otherwise the object o2.

Return Type: Object

Parameters:

  • o1 - a value to use if not null

  • o2 - a value to use instead if o1 is null

Example: to calculate the sum of Salary and Commission fields that might be null, use nvl(Salary,0) + nvl(Commission,0)

encodeToBase64( s )

Returns: the base64 encoding of s.

Return Type: String

Parameters:

  • s - string to encode

decodeBase64( s )

Returns: the base64 decoding of s.

Return Type: String

Parameters:

  • s - string to decode

decodeBase64ToByteArray( s )

Returns: byte array decoding of s.

Return Type: byte[]

Parameters:

  • s - string to decode

encodeByteArrayToBase64( b )

Returns: base64 encoding of b.

Return Type: String

Parameters:

  • b - byte[] to encode