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.
----------------------------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") }
}
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.