You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.
Join groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Need help with scripting to get all the custom fields present on the screens for a particular project for a specific issuetype, including the transition screens.
Can anyone help ?
The associations between various schemeManagers (IssueTypeScreenScheme , or FieldScreenScheme ) is very confusing.
Hi Shreyance,
A similar question like this was asked earlier and answered.
You can find the post on this link https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-get-custom-fields-based-on-project/qaq-p/555858
I hope this helps to solve your question. :)
I am looking forward to your feedback.
Thank you and Kind Regards,
Ram
Hi @Shreyance Shaw,
I came up with the script below that you can run in ScriptRunner's Script Console.
What it does is that it gets all the custom fields for all issue types of the project & then compare them with all the fields (system + custom fields) on every screen (whether the screens are applied to the workflow transition or not), then return only the custom fields as the final output.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.screen.*
import org.apache.log4j.Level
import org.apache.log4j.Logger
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)
//change the project key to your own value
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("PX")
def projectId = project?.id
log.debug "Project: $project.key | $project.name | $projectId"
//get all the custom fields for the project & all issue types
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customFields = customFieldManager.getCustomFieldObjects(projectId, []).toString()
log.debug "Custom Fields: " + customFields
def fieldScreenManager = ComponentAccessor.getFieldScreenManager()
def fieldScreens = fieldScreenManager.getFieldScreens()
def output = ""
log.debug "Screens: " + fieldScreens.name
fieldScreens.each { fieldScreen ->
def tabs = fieldScreen.getTabs()
output = output + "<h1>" + fieldScreen.name + "</h1>"
tabs.each { FieldScreenTab tab ->
output = output + "<h2>" + tab.name + "</h2>" + "<h3><u>List of Custom Fields:</u></h3>"
def items = tab.getFieldScreenLayoutItems()
items.each { FieldScreenLayoutItem item ->
if (item.getOrderableField()) {
if (customFields.contains(item.getOrderableField().name)) {
output = output + "<p>" + item.getOrderableField().name + "</p>"
}
}
}
}
}
return output
You can of course tailor this script to your requirements.
.getCustomFieldObjects() method allows you to specify the issue type of interest. Some of the transitions in your workflow may not have a transition screen. If you know the exact screen id that you're looking at, you may change the fieldScreens.each iteration (keep the code block) to:
//10000 is my screen id
def fieldScreen = fieldScreenManager.getFieldScreen(Long.parseLong("10000"))
if (fieldScreen) {
//code block
}
and you'll get the custom fields that present on a specific screen.
I hope that this helps!
If this response has answered your question, please do mark it as Accepted to make it easier for other users to discover potential solutions to their questions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This morning, Atlassian announced the acquisition of ThinkTilt , the maker of ProForma, a no-code/low code form builder with 700+ customers worldwide. ThinkTilt helps IT empower any team in their or...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.