Script Field: issuekey link

RNV February 27, 2018

Hello Everyone,
We want create a Script Fields (ScriptRunner)  that calculates the key of the linked ticket.
 Can somebody help me?

 

Thx!

 

Solution:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def linkedIssueKeys = []

for (IssueLink link in ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id)) {

linkedIssueKeys.add(link.getSourceObject().getKey())

}

return linkedIssueKeys  

 

1 answer

1 accepted

1 vote
Answer accepted
Adrián Plaza [DEISER]
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.
February 27, 2018

Hi Ruben NV,

You can try and modify this code according to your needs:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey("SCRUM-13") // get a expecific issue to test the script, comment this line after that.

def linkedIssueKeys = []

for (IssueLink link in ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id)) {

linkedIssueKeys.add(link.getDestinationObject().getKey())

}

return linkedIssueKeys

Regards,

Adrián.

RNV February 27, 2018

@Adrián Plaza [DEISER], Thx,

 

The code Return same key

Adrián Plaza [DEISER]
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.
February 27, 2018

Hi Ruben NV,


You need to comment or remove the line 6 if you put the code directly in the script field try this code:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def linkedIssueKeys = []

for (IssueLink link in ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id)) {

linkedIssueKeys.add(link.getDestinationObject().getKey())

}

return linkedIssueKeys  

 Regards,


Adrián.

RNV February 27, 2018

@Adrián Plaza [DEISER]

I change the code but need get inward links, and this:

ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.id)) 


return same issue key.

 

Thks!

RNV February 28, 2018

Final Code: 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def linkedIssueKeys = []

for (IssueLink link in ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id)) {

linkedIssueKeys.add(link.getSourceObject().getKey())

}

return linkedIssueKeys  


Thaks for help@Adrián Plaza [DEISER]
Adrián Plaza [DEISER]
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.
February 28, 2018

HI Ruben NV,

Your welcome its pleasure help you :)

Regards,

Adrián.

Suggest an answer

Log in or Sign up to answer