Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Suggest an answer

Log in or Sign up to answer
0 votes
Jia Jie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2021

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. 

TAGS
AUG Leaders

Atlassian Community Events