Forums

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

What's the order in getInwardLinks/getOutwardLinks?

Javier Sánchez February 25, 2020

I would like to get the latest destinationObject from the latest link between two issues, how am I supposed to do this? At the moment I'm getting the first element of the List but I'm not sure if the order of the list is that the latest link will be added to the first element of the List or I don't know. Should I just order it by issue id or issue key and get the latest one?

1 answer

0 votes
PD Sheehan
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.
March 4, 2020

Issue links do not store any information about when or in what order the links were created.

They are displayed in the order specified by the jira.view.issue.links.sort.order property

So if you want to know the latest issues that was linked. That's not possible from the Issue Link panel in the UI or from the IssueLinkManager

You can try to look at the most recently created issue, but that may not be the most recently linked.

The only approach that may work requires consulting the ChangeHistoryManager.

A quick console script like this worked for me:

import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.issueManager.getIssueObject('JSP-1922')

def issueLinkManager = ComponentAccessor.issueLinkManager
def changeHistoryManager = ComponentAccessor.changeHistoryManager

def linkHistory = changeHistoryManager.getChangeItemsForField(issue, 'Link')

issueLinkManager.getLinkCollectionOverrideSecurity(issue).allIssues.sort{ link->
linkHistory.find{it.to == link.key }.created
}.last()

Suggest an answer

Log in or Sign up to answer