Script Listener: Clone issue and create multiple new issue and link

Teja June 3, 2021

Hello,

I need help to create multiple issues with the same issue linking, I was able to clone an original issue and create a new issue and link it to the original issue.

Here is the script listener code:

def issue = event.getIssue()

if (issue.getIssueTypeId() == "12322" ) { //Original issue ID

def projectKey = "XYZ"
log.debug "Inside Loop"
def issueMgr = ComponentAccessor.getIssueManager()
def projectMgr = ComponentAccessor.getProjectManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
log.debug "IF ISSUE IS TYPE XXXXX CLONE ISSUE TO PROJECT YYYYY WITH SAME FIELDS, ETC"

def issueFactory = ComponentAccessor.getIssueFactory()
def newissue = issueFactory.getIssue()

newissue.setSummary (issue.summary)
newissue.setProjectObject (projectMgr.getProjectByCurrentKey(projectKey))
newissue.setIssueTypeId("12400") //The ID of the target Issue Type
newissue.description = issue.description
newissue.reporter = issue.getReporter()

def params = ["issue":newissue]
def subTask = issueMgr.createIssueObject(currentUser, params)

log.debug("issue created": newissue)
IssueLinkTypeManager issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def linkTypeName = "TCM Issues"
def linkId = issueLinkTypeManager.getIssueLinkTypes().find { it.name == linkTypeName }?.id

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.createIssueLink (newissue.getId(), issue.getId(), linkId, 1, currentUser) 
}

Any help would be really appreciated.

Thanks 

0 answers

Suggest an answer

Log in or Sign up to answer