Forums

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

How can i get all of linked Issues in Listener?

Jan Kurowski December 12, 2019

I have added a listener, that changes the priority in related issues under certain conditions, 
but when I try to get list of related issues using this code:

def idOfMainIssue=event.issue.getId()
log.warn(issueLinkManager.getOutwardLinks(idOfMainIssue))
for(item in issueLinkManager.getOutwardLinks(idOfMainIssue)){

list only consists of 2 from 6 issues that i expected to get - one is a subtask and the other is related issue(one of 5)
Code works but from log.warn(issueLinkManager.getOutwardLinks(idOfMainIssue)) i know that it doesn't see more than 2 linked issues.

I'll appreciate any help

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.bc.issue.IssueService

def change = event?.changeLog?.getRelated('ChildChangeItem')?.any{ it.field=='priority' }

if (change && event.issue.issueType.name=="Zadanie") {
log.warn("Wejszłem do pętli")
def issueManager = ComponentAccessor.getIssueManager()
def issueBNGObj= issueManager.getIssueObject(event.issue.key)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def idOfMainIssue=event.issue.getId()
log.warn(issueLinkManager.getOutwardLinks(idOfMainIssue))
for(item in issueLinkManager.getOutwardLinks(idOfMainIssue)){
def linkedIssue= item.destinationObject
def linkedIssueObj= issueManager.getIssueObject(linkedIssue.key)
def projName=linkedIssue.getProjectObject().name
String temp=linkedIssueObj.key
log.warn(temp)

if(projName=="Rejestr Potrzeb"){
log.warn("Wejszłem do if RFC? w pętli")
linkedIssueObj.setPriority(issueBNGObj.priority)
issueManager.updateIssue(event.user, linkedIssueObj, EventDispatchOption.DO_NOT_DISPATCH, false)
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def validateAssignResult = issueService.validateAssign(user, linkedIssueObj.id, linkedIssueObj.reporterId)
issueService.assign(user, validateAssignResult)
log.warn("koniec ifa wewnątrz petli")
}
}
}

 

1 answer

1 accepted

0 votes
Answer accepted
Alex Christensen
Community Champion
December 12, 2019

If you want all links, you need both outward links and inward links. When configuring issue links as a Jira admin, you can define outward and inward descriptions.

link-type-descriptions.png

Using the "Blocks" link type from my example, let's say I have the following issue link relationships configured:

  • TEST-1 - this is your main issue
    • Blocks (outward)
      • TEST-2
      • TEST-3
    • Is Blocked By (inward)
      • TEST-4
      • TEST-5
      • TEST-6

Using this line of your code assuming idOfMainIssue is the ID of TEST-1:

issueLinkManager.getOutwardLinks(idOfMainIssue)

This will only return the links to TEST-2 and TEST-3. You will also need this line of code to get the inward links, as well:

issueLinkManager.getInwardLinks(ifOfMainIssue)

You also make a note of Sub-Tasks in your problem description - in terms of Jira artifacts/objects, Sub-Tasks are treated differently and will not be retrieved using either of the methods above. You can just use this method instead to get a collection of the Issue objects that represent a given issue's Sub-Tasks:

def subtasks = issue.getSubTaskObjects() 
Jan Kurowski December 16, 2019

Thanks for Your help.

Suggest an answer

Log in or Sign up to answer