I have a script written which can delete multiple custom fields. I want to get custom fields related to a specific project. I have looked at ProjectManager and CustomFieldManager groovy documentation but there is no method that provided that. Is there a way that we can do this? I am fairly new to groovy to any help is appreciated.
Community moderators have prevented the ability to post new answers.
Hi Manmohit,
Try
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.config.ConstantsManager def projectId = ComponentAccessor.getProjectManager().getProjectByCurrentKey("JRA")?.id def cfs = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(projectId, ConstantsManager.ALL_ISSUE_TYPES)
This will return to you all the custom fields configured for the project with key JRA and all the issue types
Hi Thanos,
Thank you for the reply but I still get all the fields not the ones related to project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Manmohit,
According to the API https://docs.atlassian.com/jira/7.2.0/com/atlassian/jira/issue/CustomFieldManager.html#getCustomFieldObjects-java.lang.Long-java.lang.String-
Gets a list of custom fields for a particular project and issue type,
and of course the custom fields that have a global context as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Manmohit, you may just need to change the JRA in Thanos's script to match your project's key. If the projectId is coming back as null, then the getCustomFieldObjects() method will return all issue types. You could try something with some logging to see if you're getting your project or not.
import com.atlassian.jira.component.ComponentAccessor def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("JRA") def projectId = project?.id log.warn("Project: $project.key : $projectId") def customFieldManager = ComponentAccessor.getCustomFieldManager() def cfs = customFieldManager.getCustomFieldObjects(projectId, [])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.