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)
}
}
}
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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]]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And what's the error message?
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tuncay Senturk
Thanks for your direction here. The logging you provided ultimately led me to discovering where my issue lied.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry but could you please clarify? What's the problem here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did not check the code btw.
Before diving into the code, I just wanted to have more info.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.