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

Jira - groovy - get custom fields from screens of project

Lukas Kinc September 6, 2018

Hi,

I need get list of custom fields which I have on all of screens on a project.

Have you any advice how can I get this by groovy script?

 

Thanks

 

 

 

2 answers

Suggest an answer

Log in or Sign up to answer
3 votes
Sune Vester Lindhe July 25, 2019

Hi Lukas,

I ended up in the exactly same situation as you and solved it by:

 

//imports ad lib...

Set<String> getFieldsOnScreen(FieldScreenScheme fieldScreenScheme, IssueOperation issueOperation) {
CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
Set<String> result = new HashSet<String>()

FieldScreen fieldScreen = fieldScreenScheme.getFieldScreen(issueOperation)
fieldScreen.getTabs().each{FieldScreenTab fieldScreenTab ->
fieldScreenTab.getFieldScreenLayoutItems().each{FieldScreenLayoutItem fieldScreenLayoutItem ->
String fieldId = fieldScreenLayoutItem.getFieldId()
// I am only interested in custom fields - change appropriately
if (fieldId.startsWith("customfield")) {
CustomField customField = customFieldManager.getCustomFieldObject(fieldId)
result.add(customField.getName())
}
}
}

return result
}

Set<String> getFieldsOnScreens(FieldScreenScheme fieldScreenScheme) {
// I am only interested in Edit and View screens - change appropriately
return getFieldsOnScreen(fieldScreenScheme, IssueOperations.EDIT_ISSUE_OPERATION) + getFieldsOnScreen(fieldScreenScheme, IssueOperations.VIEW_ISSUE_OPERATION)
}

IssueTypeScreenSchemeManager issueTypeScreenSchemeManager = ComponentAccessor.getIssueTypeScreenSchemeManager()

IssueTypeScreenScheme issueTypeScreenScheme = issueTypeScreenSchemeManager.getIssueTypeScreenScheme(<My Project>)
FieldScreenScheme fieldScreenScheme = issueTypeScreenScheme.getEffectiveFieldScreenScheme(<My IssueType>)

return getFieldsOnScreens(fieldScreenScheme)
Olivier COQUILLARD October 18, 2021

Hi Sune,

the easiest way I saw on this site.

By the way, it does not take care of the "technical" fields hidden in transition screens nor postFunctions.

 

+1 anyway.

0 votes
Sune Vester Lindhe July 25, 2019

Hi Lukas,

I can show you how to get a list of all fields on the screens for a given issue if that helps.

//Sune

Adam Sasin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 9, 2023

Would you like to share with us this knowledge?

Adam Sasin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 9, 2023

im asking because i don't know how to get what custom field i have for view screen for specific issue type by groovy

Sune Vester Lindhe March 9, 2023

Hi Adam,

The code I pasted above should do it.

//Sune

TAGS
AUG Leaders

Atlassian Community Events