Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy - For current issue, possible to get all fields with name starting with string?

Rune Hellem May 29, 2020

Version

Jira v8.4.2, Scriptrunner 6.0.2-p5 

What I want to do

In our project we have a set of  issuetypes which can be both task or subtask, sharing the same screens when doing create/edit/view. If the issutype = subtask then we do not want to show some 'change management' fields. All field names starts with 'CM'. To avoid the need to update the script if adding yet another CM-field, I have tried to figure out if I can but I could not find any getFields... - only getField...

But maybe there is a reason?

While preparing the question I realize that it might be a very good reason for this not being a clever thing to so - could it have major impact on performance if needed to loop all fields every time an issue is being rendered?

1 answer

1 accepted

0 votes
Answer accepted
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2020

This may be of use to you: https://docs.atlassian.com/software/jira/docs/api/7.2.0/com/atlassian/jira/issue/CustomFieldManager.html#getCustomFieldObjects-java.lang.Long-java.lang.String-

Here's a sample implementation:

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
List<CustomField> fields = customFieldManager.getCustomFieldObjects(10800,"Request")
fields.each{field ->
if(field.fieldName[0..1] == "CM"){
//Do Stuff
}
}

Suggest an answer

Log in or Sign up to answer