Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.

Hi  @Michael Schultz 

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

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. 

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 _Snapbytes_ 

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]]

And what's the error message?

@Tuncay Senturk _Snapbytes_ 

It's 

The transitionValidation is not valid

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 _Snapbytes_ 

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

196 views 6 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you