Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,362,591
Community Members
 
Community Events
168
Community Groups

Transition Inward Linked issues

Edited

Hello. I have a script that I've been working for transitioning the linked issues of the parent issue. Basic logic is: when a parent issue is Resolved, go through each linked issue and resolve those as well. 

I am able to get all the way to validating the transition when it fails. Here is my script:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkImpl;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl

IssueService issueService = ComponentAccessor.getIssueService()

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
def actionId = 2 // change this to the step that you want the issues to be transitioned to
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def type = issue.getIssueType().getName()

log.debug("The issue type is: " + issue.getIssueType().name)

if (type.toString() == 'Task') {

List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
allInIssueLink?.each { linked ->
def linkedIssue = linked.getDestinationObject()
Long linkedId = linkedIssue.id
def transitionValidationResult = issueService.validateTransition(currentUser, linkedId, actionId,new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)

if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }

else
{ log.debug("Transition result is not valid") }
}

else {
log.debug("The transitionValidation is not valid: " + transitionValidationResult)
}
}
}

 

3 answers

1 accepted

0 votes
Answer accepted

I found the solution here. The line:

def linkedIssue = linked.getDestinationObject()

Needed to be changed to: 

def linkedIssue = linked.getSourceObject()

This gets the correct InwardLinked (Source) issues. Instead of getting the InwardLinked (Destination) issue or the "Parent" issue, which was not needed.

0 votes
Tuncay Senturk Community Leader Oct 08, 2019

I think the problem is getting the linked issues. 

You should get linked issue as below

def linkedIssue = linked.getDestinationObject()

 And then use issueId as linkedIssue.id

I hope I am not missing anything

@Tuncay Senturk 

Unfortunately, it's still not working, getting the same invalid result response. Here is the updated code with your suggestions:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkImpl;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl

IssueService issueService = ComponentAccessor.getIssueService()

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
def actionId = 2 // change this to the step that you want the issues to be transitioned to
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def type = issue.getIssueType().getName()

log.debug("The issue type is: " + issue.getIssueType().name)

if (type.toString() == 'Task') {

List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
allInIssueLink?.each { linked ->
def linkedIssue = linked.getDestinationObject()
Long linkedId = linkedIssue.id
def transitionValidationResult = issueService.validateTransition(currentUser, linkedId, actionId,new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)

if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }

else
{ log.debug("Transition result is not valid") }
}

else {
log.debug("The transitionValidation is not valid: " + transitionValidationResult)
}
}
}

 
Also, if it helps, the output of allInIssueLink in my code above is:

[com.atlassian.jira.issue.link.IssueLinkImpl@77985b01[id=227305,sourceId=523908,destinationId=406825,issueLinkType=10000], com.atlassian.jira.issue.link.IssueLinkImpl@56830a75[id=227304,sourceId=523907,destinationId=406825,issueLinkType=10000]]
Tuncay Senturk Community Leader Oct 08, 2019

And what's the error message?

@Tuncay Senturk 

It's 

The transitionValidation is not valid
Tuncay Senturk Community Leader Oct 08, 2019

Can you please replace the below code

log.debug("The transitionValidation is not valid: " + transitionValidationResult)

with this one

log.error("The transitionValidation is not valid: " 
+ transitionValidationResult?.errorCollection?.errorMessages?.join(","))

hopefully, we might understand the actual cause

@Tuncay Senturk 

Thanks for your direction here. The logging you provided ultimately led me to discovering where my issue lied.

Tuncay Senturk Community Leader Oct 10, 2019

Yeah, debugging always saves time.

I always confuse the directions, inward - source, outward - destination .

That's why I wanted to log it and see what was wrong.

Anyway, I'm glad to hear that you achieved.

0 votes
Tuncay Senturk Community Leader Oct 08, 2019

Hi  @Michael Schultz 

Sorry but could you please clarify? What's the problem here?

Tuncay Senturk Community Leader Oct 08, 2019

I did not check the code btw.

Before diving into the code, I just wanted to have more info.

Thanks

def transitionValidationResult = issueService.validateTransition(currentUser, linkedId, actionId,new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)

if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }

else
{ log.debug("Transition result is not valid") }
}

else {
log.debug("The transitionValidation is not valid: " + transitionValidationResult)
}
}
}

This is where it fails. Not a valid result. The Step ID of 2 is in fact my Closed status. Also, the Long ID of the child issues come back just fine as well. 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events