Adaptavist ScriptRunner >>> Groovy Script >>> 4 String manipulation

Atlassian Administrator/Commercial November 15, 2017

Hi to All,

in order to manipulate the Value of the the custom fileds using Groovy script, I would need to use the following features (function) that they are present in Java :

*.toLowerCase()

Math.min()

*.replace()

.substring()

It would be possible?

 

Thanks 4 the answer.

Francesco

 

2 answers

2 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2017

Groovy is a JVM based scripting languages with it's own set of idiosyncracies , here's the code snippet with requested methods - 

println 'ABCDEF'.length() // output: 6
println 'ABCDEF'.substring(1) // output: BCDEF
println 'ABCDEF'.indexOf('C') // output: 2
println 'ABCDEF'.replace('CD', 'XX') // output: ABXXEF
println 'ABCDEF'.toLowerCase()

 Math class is available from the JVM itself at run-time thus groovy can use it as well. "Math.min (1,2)"  will return smaller of the two numbers.

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2017

Hello, 

Yes, it is possible. Groovy is based on Java that is why you can just use pure Java there. That would be a simple script which you can try in Script Console

def str = "String"
log.error(str.toLowerCase())
log.error(Math.min(2,1))
log.error(str.replace("t", "r"))
log.error(str.substring(1, 2));

Suggest an answer

Log in or Sign up to answer