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:
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
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
.getParentObject()
).getEpic()
)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
}
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.