Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,958
Community Members
 
Community Events
168
Community Groups

Unable to find a method to get the field configurations in jira using script runner

Hi Team,

We are unable to find a method to get the field configurations in jira using script runner.
Kindly let us know if we can list all field configurations and check its corresponding field configuration scheme.
We need this to performing cleanup jobs using scriptrunner.
Please advise.

1 answer

Hi @Anusha Raju _US_

For your requirement, you can try to invoke the FieldConfigSchemeManager object using the ComponentAccessor and filter the field configuration you are looking for.  

Something like:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContextImpl

def projectManager = ComponentAccessor.projectManager
def fieldConfigSchemeManager = ComponentAccessor.fieldConfigSchemeManager
def customFieldManager = ComponentAccessor.customFieldManager

def project = projectManager.getProjectByCurrentKey('MOCK')
def issueContext = new IssueContextImpl(project.id, "10004") // project id and issue type id (Bug)

def sampleTextField = customFieldManager.getCustomFieldObjectsByName('Sample Text Field').first()

log.warn "====>>> ${fieldConfigSchemeManager.getRelevantConfig(issueContext, sampleTextField).name}"

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to modify it accordingly.

In this example, I am only looking for the Schema of one field, i.e. Sample Text Field. You will need to modify the code accordingly.

I have tested this code on the ScriptRunner Console. Below is a screenshot for your reference:-

image1.png

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram 

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thank you so much for the suggestion.

Here I don't want the information specific to any project or issuetype.

I need a list of all field configurations in our jira instance. I need the field configurations as its is displayed on the Issues >> Field Configuration Section.

I am trying to get a list and then check if it's linked to any Field Configuration Scheme.

If not I need to delete the Field Configuration.

I need to schedule this as a job to perform this cleanup monthly.

Thanks & Regards

Anusha Raju

Hi @Anusha Raju _US_

If you want it to print all the field configurations irrespective of the project or issue type, you can try something like:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.project.Project

def projectManager = ComponentAccessor.projectManager
def fieldConfigSchemeManager = ComponentAccessor.fieldConfigSchemeManager
def customFieldManager = ComponentAccessor.customFieldManager
def projects = projectManager.projects

def output = new File('/temp/output.txt')
output.createNewFile()

def fileWriter = new FileWriter(output)

projects.each { Project project ->
project.issueTypes.each { IssueType issueType ->
customFieldManager.customFieldObjects.each { CustomField customField ->
def issueContext = new IssueContextImpl(project.id, issueType.id)
def fieldSchema = fieldConfigSchemeManager.getRelevantConfig(issueContext, customField)
if (fieldSchema) {
fileWriter.write("${fieldSchema.name}\n")
}
}
}
}

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

The ScriptRunner console can only print a maximum of 300 lines. If the total number of lines exceeds this limit, it will be truncated and not displayed, which is why I modified the code to write to a text file instead.

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

An update on Jira Software customer feedback – June 2022

Hello Atlassian Community! Feedback from customers like you has helped us shape and improve Jira Software. As Head of Product, Jira Software, I wanted to take this opportunity to share an update on...

5,048 views 18 32
Read article

Atlassian Community Events