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: Code Block |
---|
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: Code Block |
---|
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: Code Block |
---|
scores["Pete"] = 3
|
To get the size of the collection, you can use the size() function: Looping is provided using the each() closure: Code Block |
---|
myList.each() {
if (it > 0) {
return it;
}
}
|
SamplesConvert bank account number to bank nameLet 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: Code Block |
---|
def bankCodes = [ '0100' : 'KB', '0800' : 'CSOB'
];
code = right(value(), 4)
return bankCodescode ? bankCodescode : 'Other'
|
|