Forums

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

Why inwardLink.isSystemLink() returns iteslf instead a single (parent) result?

Cedacri
Contributor
March 18, 2025

I've recently found out about isSystemLink() method for links in ScriptRunner, while the documentation is lacking, the method seems to always return true for the children of an issue as seen in the code bellow, so Ive crafted this getChildren() nifty function that is very helpful to me in filtering other links and getting the children of any type of issue based on it

 

def getChildred(Issue issue) {
    def outwardLinks = issueLinkManager.getOutwardLinks(issue.id)
    def children = []

    outwardLinks.each { child ->
        if (child.isSystemLink()) {
            children << child.getDestinationObject()
        }
    }

    return children
}

Extremely helpful!

 

Now that I found how to getChildren(), I should be able to also getParent(), by using the same logic in reverse, right? Wrong, for some reason the inwardLinks.isSystemLink() always seem to return itself instead of the parent link:

image.png

 

Thoughts on how to make getParent() return what I want? Scriptrunner has getParentObject() but it does not return Initiatives and I have to get the Parent Link and use hoops from there to get it when needed and also for Epics I have to use getEpic() instead of a single method that can be used anywhere, also for Stories its getStory() but it works only on the matching subtasks/tasks. 

I need a singular function that would return the parent issue everywhere

 

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk
Community Champion
March 18, 2025

Hi @Cedacri 

You're right, there is not one function that fits all. 

So, you have to handle all, let me list what parent can be for each case and then try to code accordingly

 

  • case 1: Sub-task → Parent (.getParentObject())
  • case 2: Story → Epic (.getEpic())
  • case 3: Epic → Parent ('Parent Link', this is a custom field)
  • case 4: Then finally falls back to searching inwardLinks with .isSystemLink() if you have a custom advanced hierarchy.

I tried to code the getParent function as below, but I haven't tested it so please be aware that it might not fit all cases.

def getParent(Issue issue) {
// case1: Sub-task → Story/Task
if (issue.isSubTask()) {
return issue.getParentObject()
}

// case 2: Story/Task → Epic (via Epic Link)
def epicLinkField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Epic Link")
if (epicLinkField) {
def epic = issue.getCustomFieldValue(epicLinkField)
if (epic instanceof Issue) {
return epic
}
}

// case 3: Epic → Initiative (via Parent Link)
def parentLinkField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Parent Link")
if (parentLinkField) {
def parent = issue.getCustomFieldValue(parentLinkField)
if (parent instanceof Issue) {
return parent
}
}

// case 4: Fallback: system inward link (other hierarchies)
def issueLinkManager = ComponentAccessor.issueLinkManager
def inwardLinks = issueLinkManager.getInwardLinks(issue.id)

def parentLink = inwardLinks.find { link ->
link.isSystemLink() && link.getSourceObject().id != issue.id
}

if (parentLink) {
return parentLink.getSourceObject()
}

return null
}

 

Suggest an answer

Log in or Sign up to answer