BellaDati supports all Arrays from https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html and ArrayUtils from https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/ArrayUtils.html.

Syntax: first define name of the package, then use desired method.

Example:

def int[] a = [1,2,3]
a = ArrayUtils.add(a, 0)
Arrays.sort(a)
return a[3]

 

The transformation script has built-in support for two important data types, lists and maps (Lists can be operated as arrays in Java language). Lists are used to store ordered collections of data. For example an integer list of your favorite integers might look like this:

emptyList = []
myList = [1776, -1, 33, 99, 0, 928734928763]
return [0]

Another native data structure is called a map. A map is used to store "associative arrays" or "dictionaries". That is unordered collections of heterogeneous, named data. For example, let's say we wanted to store names with IQ scores we might have:

emptyMap = [:]
scores = [ "Brett":100, "Pete":"Did not finish", "Andrew":86.87934 ]
return scores["Pete"]

To add data to a map, the syntax is similar to adding values to an list. For example, if Pete re-took the IQ test and got a 3, we might:

scores["Pete"] = 3

To get the size of the collection, you can use the size() function:

scores.size()

Looping is provided using the each() closure:

myList.each() {
  if (it > 0) {
    return it;
  }
}

Samples

Convert bank account number to bank name

Let the column cell contains a full bank account number (eg. "54-123456789/0100") and we transform it to the bank name according to last 4 digits. The script is:

def bankCodes = [ '0100' : 'KB', '0800' : 'CSOB'
];
code = right(value(), 4)
return bankCodescode ? bankCodescode : 'Other'
  • No labels