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

Get ID of custom dropdown value using groovy

Mark Love Jul 06, 2014

Hi,


I'm writing a Jira Behviours script that accesses the epic linked to the current issue, and I then need to get the value of a custom dropdown of the epic

My script works ok, and can access the field, but getCustomFieldValue returns the string value of the drop down ("Team"), whereas I need the underlying integer ID (since the string values are not unique, due to different contexts)

How can I adapt my script so that it gets the ID, rather than the string value?

cfTeam = customFieldManager.getCustomFieldObjectByName("Team")
def epicTeam = epic.getCustomFieldValue(cfTeam)

I though adding .value, or value(), or specifying the variable as an int or double would do it, but it doesn't seem to

Thanks

Mark.

1 answer

1 accepted

1 vote
Answer accepted
JamieA Jul 06, 2014

I don't think this is related to behaviours... this is just jira's API I think.

getCustomFieldValue - will return an Option object for a single select. If you toString() it you will get the option value, but that's not what it actually returns.

Try:

epic.getCustomFieldValue(cfTeam)?.optionId


Mark Love Jul 06, 2014

Fantastic, that worked first time. Thanks.

Where could I have found this in the API documentation - I feel like I'm stabbing in the dark here trying to find the right syntax and methods.

JamieA Jul 06, 2014

And don't worry... just give it 7 to 8 years of doing this on a constant basis and it will become second nature.

JamieA Jul 06, 2014

If it was me, I would have printed the return type, ie:

log.debug epic.getCustomFieldValue(cfTeam).getClass().name

You can't really do any alternative because the return type for getCustomFieldValue is just Object.

Once you have the class you can use the javadoc: https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/customfields/option/Option.html

Setting up an IDE and debugging makes this easier.


Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

530 views 0 4
Join discussion

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