Through a workflow post function I am trying to create / clone a new ticket while linking it to ticket number mentioned in a custom field.
We have both the JMWE and Scriptrunner plugin.
I've tried to accomplish this with the "Create / Clone issue(s) (JMWE app)" post function and I've added the script below in the "Post-creation script" section. The ticket get's created fine but there's no link set.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.getIssueManager()
def key = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11201")
def cFieldValue = issue.getCustomFieldValue(key)
doAfterCreate = {
def issueToLinkTo = issueManager.getIssueByCurrentKey("cFieldValue")
def duplicateLinkTypeName = "Duplicate"
def duplicateLinkType = issueLinkTypeManager.getIssueLinkTypesByName(duplicateLinkTypeName)
if (!duplicateLinkType) {
log.warn("Issue link type with name: ${duplicateLinkTypeName} does not exist")
} else {
issueLinkManager.createIssueLink(issue.id, issueToLinkTo.id, duplicateLinkType[0].id, 1, currentUser)
}
}