Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy script to split label values

Need help on splitting the label values based on text.

Label field values are [June_2019_POA1, ABC, July_2020_POA2, XYZ]

So I need to find POA1 and POA2 values exist or not in label.

If the values exist then get them and assign the values to 2 different variables.

FirstPOA1 = JUNE_2019

SecondPOA2 = July_2020

Can anyone help on this plz?

1 answer

1 accepted

0 votes
Answer accepted

Regex will be your friend for that.

I often use this for reference: https://regex101.com/r/1BscV3/2

Here is how you can use that in groovy:

def labels = ['June_2019_POA1', 'ABC', 'July_2020_POA2', 'XYZ']
def regexPat = /^([a-z|A-Z]*_\d{4})_(\S*)$/
def fieldMap = [POA1:'FirstPOA1', POA2:'SecondPOA2']
def FirstPOA1, SecondPOA2
labels.each{ label->
def matcher = label =~ regexPat
if(matcher.matches()){
if(matcher[0][2] == 'POA1') FirstPOA1 = matcher[0][1]
if(matcher[0][2] == 'POA2') SecondPOA2 = matcher[0][1]

}
}
log.info "FirstPOA1 = $FirstPOA1"
log.info "SecondPOA2 = $SecondPOA2"

Hi @Peter-Dave Sheehan This script works but need one small changes on it to convert the string to date format. I am looking the output format would be like 06/01/2019 and 07/01/2020.

 

def fmtfrsPOA1 = FirstPOA1.replaceAll("_",",")
Date dtfirstPOA1 = (Date)fmtfrsPOA1
def dtfirstPOA1format = dtfirstPOA1.format('MM-yyyy')

I tried above but through error. Any help much appreciated. 

Try parsing the poa value as-is by providing the existing format (rather than converting), then format it in the desired format.

new Date().parse( 'MMMM_yyyy',FirstPOA1 as String).format('MM/dd/yyyy')

Its worked. You have solved my issue. Thank you so much

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.4
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you