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")
}
}
}
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.
Using the "Blocks" link type from my example, let's say I have the following issue link relationships configured:
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.