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.
Hi @Anusha Raju
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:-
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Anusha Raju
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_
Your sample is listing the configuration for all Fields,
I think what is wanted is to obtain a list of all 'Field Configurations' that would be displayed at:
<JiraInstance>.com/secure/admin/ViewFieldLayouts.jspa
What about the Field Configurations that are not part of a Configuration Scheme assigned to a Project?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.