Loop for all field with value in issue

Hello :)


i would like to know if it possible to loop through all fields with value for an issue and how this can be acheived with scriptrunner?

Any guidance is very well appreciated. 




1 answer

1 accepted

0 votes
Answer accepted

This would return all the List of all customfields on the issue. 

You can then loop throught them and and whatever you're trying. 

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def issueObject = issueManager.getIssueObject("HW_TEST-64")

def customFieldObjects = customFieldManager.getCustomFieldObjects(issueObject)

Thank you so much!!!


Very helpful, is there a way to get customfield only visible for that particular issue / project & issuetype or in a certain screen scheme.


i have 730 customfield in the database and it might take a while to through all that in a loop. 


Thanks for your help!


If all your custom fields are shared in global context, meaning they are configured to be shared with all issues and all the projects, then all those fields will appear.
That is because, even though they may not be present or have any values present for the current issue, but the current issue still could access them through their system if need be,

So unfortunately, it would return all the fields becauase technically all the fields 'are available' to the issue. 

Ahh thank you so much! Very much appreciated. 

I probs will need to for loop through all the fields and see if there is value in them. 

Unless you think there is a better route? :)



Well if it is just one custom field you are trying to find, then you can get an object of that custom field, and search it from all the fields. 

For e.g. 
you could do something like this:

def cf = customFieldManager.getCustomFieldObject(11602)

customFieldObjects = customFieldManager.getCustomFieldObjects(issueObject)
def totalValue = 0;
if (customFieldObjects.contains(cf))
// your code for what you want to do

 what is it that you're trying to do though? 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


246 views 0 6
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