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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,467
Community Members
 
Community Events
184
Community Groups

Clone Field Screens Programmatically in groovy script.

Edited

Hi All, 

Currently I'm creating groovy script that will copy project's  issue type screen scheme, keeping hierarchy of issue type screen scheme eg. 

Issue Type screen scheme
   Screen scheme 
     Field Screen -Create, EDIT, View  


I find some method to do that but its not working.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.scheme.SchemeEntity
import com.atlassian.jira.issue.fields.screen.FieldScreen
import com.atlassian.jira.issue.fields.screen.FieldScreenScheme
import com.atlassian.jira.issue.fields.screen.FieldScreenSchemeManager
import com.atlassian.jira.issue.issuetype.IssueType

def projectKey = "PROJ" // replace with the project key
def newSchemeName = "Clone of ${projectKey} Issue Type Screen Scheme"

// get the ProjectManager, IssueTypeScreenSchemeManager, and FieldScreenManager
def projectManager = ComponentAccessor.getProjectManager()
def issueTypeScreenSchemeManager = ComponentAccessor.getIssueTypeScreenSchemeManager()
def fieldScreenManager = ComponentAccessor.getFieldScreenManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// get the existing issue type screen scheme for the project
def project = projectManager.getProjectObjByKey(projectKey)
if (project == null) {
log.error("Project not found: ${projectKey}")
return
}
def scheme = issueTypeScreenSchemeManager.getIssueTypeScreenSchemeFor(project)
if (scheme == null) {
log.error("Issue Type Screen Scheme is null for project ${projectKey}")
return
}

// clone the issue type screen scheme
def newScheme = issueTypeScreenSchemeManager.copyIssueTypeScreenScheme(scheme)
newScheme.setName(newSchemeName)
issueTypeScreenSchemeManager.createIssueTypeScreenScheme(newScheme, currentUser)

// clone the screens for the new scheme
scheme.getEntities().each { SchemeEntity schemeEntity ->
if (schemeEntity.isOfType(IssueType.class)) {
def issueType = schemeEntity.getEntity()
def existingScreen = schemeEntity.getScheme()
def newScreenName = "Clone of ${existingScreen.getName()} for ${newSchemeName} (${issueType.getName()})"

def newScreen = fieldScreenManager.copyFieldScreen(existingScreen)
newScreen.setName(newScreenName)
fieldScreenManager.createFieldScreen(newScreen)

// associate the new screen with the new scheme and issue type
def newEntity = newScheme.getEntities().find { it.getEntity()?.getId() == issueType?.getId() }
if (newEntity == null) {
log.error("Issue Type ${issueType?.getName()} not found in new Issue Type Screen Scheme")
return
}
newEntity.setScheme(newScreen)
issueTypeScreenSchemeManager.updateIssueTypeScreenSchemeEntity(newEntity, currentUser)
}
}


  

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events