Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get all custom fields of a project using Scriptrunner

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.

 

 

 

2 answers

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.

2021-03-23_10-21-06.png

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.

Suggest an answer

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

ThinkTilt is joining the Atlassian Family!

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...

255 views 16 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you