Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,921
Community Members
 
Community Events
176
Community Groups

How to get only the key from groovy when running .getCustomFieldValue()

Hi All,

I've  a groovyscript where i want to find an objectID of a field from inside. It succeeds partially.

i use:

def app_newcustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14100");
def app_newValue = issue.getCustomFieldValue(app_newcustomField);

And as result i get :

app_newValue = [Interne Test apparaat (DM-453739)]

I only want the Key DM-453739 and not also the label. 

Can somebody help me with the right notation to get it?

Thx

 

 

 

1 answer

1 accepted

0 votes
Answer accepted

Hi @Ron Lambregts 

 

I guess you are using a field that is not a standard type field.

 

First, do you expect 1 or multiple values ?

If only one you can get rig of the [ ] using first() fucntion.

def app_newcustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14100");
def app_newValue = issue.getCustomFieldValue(app_newcustomField)?.first();

 

Then you can use a regex to get what is between the ().

 

Regex is (?<=\()(.*?)(?=\))

 

The code should be something like

app_newValue =  (app_newValue =~ / (?<=\()(.*?)(?=\))/)[ 0 ]​[ 1 ]

 

You may have to add some code to validate there is something that have match

 

HI @Florian Bonniec  it helped me a lot. Thx !

Suggest an answer

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

Atlassian Community Events