scriptrunner link jira issue? Edited

I am using jira build-in post to Clones an issue and links ,and try to link original issue with new issue,

 however issue.id is null, not sure why?

 

Could @Thanos Batagiannis [Adaptavist] , @Jamie Echlin [Adaptavist] or some of the other Adaptavist guys please help me out here?

 

1 answer

Hey 

I think that the Do After Create actions in the documentation is what you need. There is also there an example similar to what you want to achieve. 

Regards, Thanos

Thanos,

I did try code below, but got some error:

line 12 cannot find matching method.

When creating an issue A, I use the "Clone an issue and links" post function on the creation transition.
This creates a clone issue, issue B, 

I want to link  issue A to clone issue B, should I use sourceIssue.id or originallissue.id

Could you help me take a look?

@Thanos Batagiannis [Adaptavist]

import com.atlassian.jira.component.ComponentAccessor 
import com.atlassian.jira.issue.link.IssueLinkTypeManager
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.getIssueManager()
doAfterCreate = {
def issueToLinkTo = issueManager.getIssueByCurrentKey(sourceIssue.id.toString())
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)
}
}

 

 

I just reread your question and I am a bit confused. In the clone issue and links there is a dropdown - Issue Link Type / Direction - where you can set a link from original issue to the issue that just got created, you do not need to add any custom script ...

Did you try to make use of that dropdown and failed ?

regards, Thanos

@Thanos Batagiannis [Adaptavist] 

Following are the detail:

When creating an issue A, I use post function Clone Issue and Link  on creation transition. And this will create a clone issue B, then automatically link issue A to issue B.

So I add follow code in 'Clone issue and Link' - Additional issue actions:

import com.atlassian.jira.component.ComponentAccessor 
import com.atlassian.jira.issue.link.IssueLinkTypeManager
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.getIssueManager()
doAfterCreate = {
def issueToLinkTo = issueManager.getIssueByCurrentKey(sourceIssue.id.toString())
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)
}
}

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,126 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you