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

Hi All, I want to change the status of the ISSUE as soon as all its corresponding linked issues are

Hi All, I want to change the status of the ISSUE as soon as all its corresponding linked issues are closed. I have written a below script but this does not seems to be working

please find the below script -

The below script is not updating the status of the  issue.

  • Suppose I Have Issue A and Issue B , Issue A is in Source Project and Issue B in Destination Project
  •  Issue A has several issues linked to it out of which one is ISSUE B then as soon as the Issue B is closed then the status of Issue A should also be change either could be closed or anything
  • I have placed the below script in the post function of Closed status of Issue A but still the status of Issue A is not getting Updated as soon as the Issue B gets closed.

----------------------------Script...............................................................................................

import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 31
def transitionValidationResult
def transitionResult

List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator OutIterator = allOutIssueLink.iterator(); OutIterator.hasNext();) {
IssueLink issueLink = (IssueLink) OutIterator.next();

def linkedIssue = issueLink.getDestinationObject().id
transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
}

1 answer

Hi @shrikant maheshwari,

The sample script below shows closing the Issue A as "Done" when ALL its Outward Linked Issues (Issue B) are closed as "Done" which you can refer to:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl

// the name of the action you want to move the issue to
final String actionName = "Done"

//ENABLE it if executing the script in Script Console
//def issueManager = ComponentAccessor.issueManager
//def issue = issueManager.getIssueByCurrentKey("ABC-1")

def workflow = ComponentAccessor.workflowManager.getWorkflow(issue)
def actionId = workflow.allActions.findByName(actionName)?.id
def issueLinkManager = ComponentAccessor.issueLinkManager

def allDone = true

def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser


List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator OutIterator = allOutIssueLink.iterator(); OutIterator.hasNext();){
IssueLink issueLink = (IssueLink) OutIterator.next();

String linked = issueLink.destinationObject
def linkedIssue = issueManager.getIssueByCurrentKey(linked)

if(linkedIssue.getStatus().name != "Done"){
allDone = false
}
}

//If all linked issues are closed as "Done"
if(allDone){
def transitionValidationResult = issueService.validateTransition(loggedInUser, issue.id, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(loggedInUser, transitionValidationResult)
if (transitionResult.isValid()){
log.warn("Transitioned issue $issue through action $actionId")
}else{
log.warn("Transition result is not valid")
}
}else{
log.warn("The transitionValidation is not valid")
}
}

 

Here's the community post that might be helpful for your references:

If you like to skip permissions, validators or conditions, you can use the TransitionOptions.Builder() class. 

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

334 views 9 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