scriptrunner link jira issue?

Qi Jiang October 12, 2017

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 _ScriptRunner - The Adaptavist Group_ or some of the other Adaptavist guys please help me out here?

 

1 answer

1 vote
Thanos Batagiannis _Adaptavist_
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 13, 2017

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

Qi Jiang October 13, 2017

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

 

 

Thanos Batagiannis _Adaptavist_
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 13, 2017

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

Qi Jiang October 13, 2017

@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
TAGS
AUG Leaders

Atlassian Community Events