Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create ticket with link from custom field value

Atlassian TMG October 12, 2023

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)
}
}

1 answer

1 accepted

1 vote
Answer accepted
Suprija Sirikonda _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 12, 2023

Hello @Atlassian TMG!

I understand you want to link the ticket, entered in customfield_11201, to the new ticket created using Create/Clone Issue(s) JMWE post-function.

What's the type of customfield_11201? Will users manually enter an issuekey in this field?

Regards,

Suprija | Appfire

Atlassian TMG October 12, 2023

Hi @Suprija Sirikonda _Appfire_ 

Thank you for the fast reply. This field is a "Single Issue Picker" but I've also tried to see if it works with a "text field (single line)" but it doesn't work either.

Suprija Sirikonda _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 12, 2023

Hi @Atlassian TMG,

If the field is of type "Single Issue Picker", add the below script in "Post-creation script" of the JMWE Create/Clone issue(s) post-function: 

if(issue.get("customfield_11201"))
newIssue.linkIssue("is duplicated by",issue.get("customfield_11201")) 

Replace

  • 11201 with ID of the "Single Issue Picker" field
  • is duplicated by with the desired link name.

I hope this helps!

Regards,

Suprija | appfire

Atlassian TMG October 12, 2023

Hi @Suprija Sirikonda _Appfire_ , thank you. It works.

Suggest an answer

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

Atlassian Community Events