Scripts provided here are typically Javascript so will likely not work if directly pasted into a Groovy script editor, some tweaking may be required.
import java.util.regex.Pattern; def pattern = Pattern.compile("([Gg])roovy") assert pattern.class == Pattern; print('pattern class: '+pattern.class); |
var p = java.util.regex.Pattern.compile("test"); |
var x = java.util.List.of("this","that"); print(x.getClass() + " has "+x.size() +" elements"); print("0 = "+x.get(0)); print("1 = "+x.get(1)); |
Reuse of common loop variables in ‘for’ seems to break, use unique name for different loops.
Some javascript functions are not available in the Java ScriptEngine implementation, eg ‘in' and ‘list.includes’ are not supported, in such cases, you should implement a script to do the work, eg, here we work on to: and cc: to test if they are mailbox addresses referred in the common list:
var addresses=["mailbox1@dom.com", "mailbox2@dom.com"]; function hasAddress(testAddr) { var ret=false; for (i = 0; i < addresses.length; i++) { if (testAddr === addresses[i]) { ret=true; break; } } return ret; } if (toAddresses) { for (j = 0; j < toAddresses.length; j++) { var isListed = hasAddress(toAddresses[j].getAddress()); if (isListed) { print('to['+j+'] = '+toAddresses[j].getAddress() + ", isMailbox: "+isListed); } } } if (ccAddresses) { for (k = 0; k < ccAddresses.length; k++) { var isListed = hasAddress(ccAddresses[k].getAddress()); if (isListed) { print('cc['+k+'] = '+ccAddresses[k].getAddress()+ ", isMailbox: "+isListed); } } } |
The following are scripts to solve some cases, may help you toward a solution, feel free to submit yours through support or comments!