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)
}
}
Hi @FCCjira
Were you able to get the code to work?
I am asking this because there is no straightforward approach to achieving your requirement.
However, if you can get this to work, it would be great to know how you managed this.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.