Forums

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

Scriptrunner inward links help

Jamie Rogers
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.
December 4, 2019

Hi Community

I need some further assistance with a scripted field which I don't think is working correctly - not sure what is wrong but hopefully someone can assist.

The purpose of the field is just to return the issue key for linked issues of a specific link type, and this has been narrow down to return results only from specific projects. It appears however for inwards links it is not returning correct results.

My example issue (EDE-119) has inward links to END-2346 (is related to) however my script below returns the issue's own key instead (EDE-119) which is not expected. It appears to return its own issue key as in another example there were 6 END issues linked via this type and the result was itself 6 times.

Something is definitely wrong somewhere but I am still learning and cannot figure it out.

import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()

def retVal = ''

// Get only outward links
def links = issueLinkManager.getInwardLinks(issue.id)

def itr = links.iterator()
while (itr.hasNext()) {
def link = itr.next()

// Only care about "is related to" link types
if (link.issueLinkType.name != 'Relates') {
continue
}

// Only care about linked issue of given projects
def allowedProjects = ['EDE', 'END']
if (!allowedProjects.contains(link.destinationObject.projectObject.key)) {
continue
}

// Get other issue
def linkedIssue = link.destinationObject

// Line seperators if more than one ticket
if (retVal != '') {
retVal += '<br>'
}
retVal += "${linkedIssue.getKey()} "
}

return retVal

I appreciate any assistance that can be offered.

Regards, Jamie  

1 answer

1 accepted

0 votes
Answer accepted
Damian Wodzinski
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.
December 4, 2019
def link = itr.next()

This fragment pulls the inward Issue, so it would be "END-2346" but then you grab the destination Object:

def linkedIssue = link.destinationObject

So you are going back to "EDE-119". Just change it:

def linkedIssue = link.sourceObject  // I do not know if this method is correct, I was using different one: getSourceObject()

 

Jamie Rogers
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.
December 5, 2019

Hi @Damian Wodzinski 

Thanks for the assistance - this is very helpful and works perfectly.

I had to update link.sourceObject in one other place in my script where the return results are filtered down by specific project keys.

Regards, Jamie 

Suggest an answer

Log in or Sign up to answer