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
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()
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.