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 vote
Tayyab Bashir Community Champion Sep 07, 2017

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!


Tayyab Bashir Community Champion Sep 07, 2017

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? :)



Tayyab Bashir Community Champion Sep 13, 2017

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

358 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