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

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

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 vote
Alexey Matveev Community Champion Nov 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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

171 views 1 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you