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

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

Return field names based on value

I have a number of custom fields (radio buttons) with simple Yes/No values attached to them. I need a scripted field to return the field names of all fields in that issue with a "Yes" value.

I imagine this is pretty easy to accomplish but am having a tough time. Any help would be so greatly appreciated!

1 answer

1 accepted

Hi Clayton,

This is totally achievable. I've written the below script which will work in your scenario with a few minor modifications:

import com.atlassian.jira.component.ComponentAccessor

// Define resources
def customFieldMgr = ComponentAccessor.getCustomFieldManager()

// Do away with this in the field
def issueManager = ComponentAccessor.getIssueManager()

// Define the fields we want to check
def questions = ["First Question",
"Second Question",
"Third Question"] // <-- Change these for the names of the fields you want to check

def result = []

// Check the result of those fields and build output.
questions.each {
def field = customFieldMgr.getCustomFieldObjectByName(it)
if (field) {
def opt = issue.getCustomFieldValue(field)
if (opt && opt.getValue() == "Yes") {
result.add(it)
}
}
}

result

 All you need to do is change the values in the questions variable to the names of your radio fields that you wish to check. This script should then work for you.

I hope this helps! Just reply if you have any questions :-)

Thank you! That is exactly what I'm looking for. Also really helpful, as I am trying to learn to implement Script Runner on a deeper level that the built-in scripts/JQL functionality. This is very clear and helpful. Thank you so much!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

134 views 1 0
View question

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