Forums

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

Get a list of Field Configurations using ScriptRunner

David Harkins
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.
January 27, 2024

I am looking for a way to list / iterate through all the 'Field Configurations' which are displayed on the screen: https://jira.***.com/secure/admin/ViewFieldLayouts.jspa

This needs to be regardless of Project or 'Field Configuration Scheme'

Once i can do that, then the intention is to go through each and make adjustments as required.

2 answers

1 vote
PD Sheehan
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.
January 30, 2024

You should be able to use the getEditableFieldLayouts() method to get all your layouts.

 

import com.atlassian.jira.component.ComponentAccessor

ComponentAccessor.fieldLayoutManager.editableFieldLayouts.collect{"$it.id: $it.name"}.join('<br>')

 

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
January 28, 2024

As far as I know, you can't directly get all field configurations without a project or field config layout. To list or iterate through all field configurations, you'd typically need to go through the schemes and then get the configurations associated with them. 

You can navigate through the projects, field configuration schemes, and field configurations. Here’s an approach which might help:

  1. Retrieve all projects
  2. For each project, get field configuration scheme
  3. From the field configuration scheme (by issue types), access the field configurations

Here is a code you can start with:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutManager
import com.atlassian.jira.issue.fields.layout.field.FieldLayout

ProjectManager projectManager = ComponentAccessor.getProjectManager()
FieldLayoutManager fieldLayoutManager = ComponentAccessor.getFieldLayoutManager()

// List to hold all unique field configurations
Set<FieldLayout> allFieldConfigs = new HashSet<>()

// provide issue type ids to retrieve field configurations for
Collection<String> allIssueTypeIds = ... //

// Iterate through all projects
projectManager.getProjectObjects().each { project ->
// Get the Field Configuration Scheme for the project
def fieldConfigScheme = fieldLayoutManager.getFieldConfigurationScheme(project)


fieldConfigScheme.getAllFieldLayoutIds(allIssueTypeIds).each { fieldLayoutId ->
// Get the FieldLayout (Field Configuration)
FieldLayout fieldLayout = fieldLayoutManager.getFieldLayout(fieldLayoutId)
allFieldConfigs.add(fieldLayout)
}
}

// Now you have all field configurations

allFieldConfigs.each { fieldLayout ->
log.info "Field Configuration Name: ${fieldLayout.name}"
}




 

I hope it helps.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.12
TAGS
AUG Leaders

Atlassian Community Events