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 Register to answer

Stay in touch

Be the first to know what's trending on Atlassian Community