Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Script Runner - How to add a field on screen

How can I add a field on a project's field configuration and on the screens.

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 05, 2023

Hi @Radhika Shinde 

I can't say I 100% understood your post but I think you can start with the below code.

 

import com.atlassian.jira.component.ComponentAccessor 
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.screen.FieldScreen
import com.atlassian.jira.issue.fields.screen.FieldScreenTab
import com.atlassian.jira.issue.fields.screen.FieldScreenScheme
import com.atlassian.jira.issue.fields.screen.FieldScreenSchemeManager
import com.atlassian.jira.util.ErrorCollection

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField customField = // your custom field to add to the screen

FieldScreenSchemeManager fieldScreenSchemeManager = ComponentAccessor.getComponent(FieldScreenSchemeManager.class)
FieldScreen fieldScreen = fieldScreenSchemeManager.getFieldScreen(FieldScreen.DEFAULT_SCREEN_ID)
// Get field screen tab (assuming you have only one tab or add to the default tab)
FieldScreenTab fieldScreenTab = fieldScreen.getTab(0)
// Add custom field to field screen tab
fieldScreenTab.addFieldScreenLayoutItem(customField.getId())
// Update field screen
fieldScreenSchemeManager.updateFieldScreen(fieldScreen)

List<FieldScreenScheme> fieldScreenSchemes = fieldScreenSchemeManager.getFieldScreenSchemes()
// add custom field to each scheme
for (FieldScreenScheme scheme : fieldScreenSchemes) {
scheme.addFieldScreen(fieldScreen)
ErrorCollection errorCollection = fieldScreenSchemeManager.updateFieldScreenScheme(scheme)
if (errorCollection.hasAnyErrors()) {
log.error(
"Error adding custom field to field screen scheme: " + errorCollection.getErrorMessages())
}
}


Hello @Tuncay Senturk ,

Check your code once. I don't think this is a right code.

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 29, 2023

Hi @Bhakti Prasad Panda 

Thanks for your message, why do you think it is not the right code?

Hello @Tuncay Senturk ,

Please put the code in script console of scriptrunner. It will show you the errors.

We are using Jira 9.4.7 and i hope you're using the same so if you can refer below Java APIs, you won't find the methods (you've used in your code) in the article:

https://docs.atlassian.com/software/jira/docs/api/9.4.7/com/atlassian/jira/issue/fields/screen/FieldScreenSchemeManager.html

The methods are available in FieldScreenManager i suppose:

https://docs.atlassian.com/software/jira/docs/api/9.4.7/com/atlassian/jira/issue/fields/screen/FieldScreenManager.html

I would be glad too if i am wrong in here :) but just got this observation.

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 29, 2023

Yes, you are right, this is quite old version I suppose. They (FieldScreenSchemeManager) need to be changed (to FieldScreenManager)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.11
TAGS
AUG Leaders

Atlassian Community Events