Hi everyone,
I'm trying to do some condition with script runner.
The goal is showing a transition with à warning (because last tash to go on done status) when all task associated with issue link are done but one (the one i'm making the transition). Else we show a classic transition.
I created 2 differents transitions and fix transition as following (with opposite check in the last bloc for the second transition):
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.bc.issue.IssueService;
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.IssueInputParametersImpl;
IssueService issueService = ComponentAccessor.getIssueService()
// Récupération de l'ID du PARENT de la tâche
def parentIssueId = issue.getParentObject()?.getId()
log.debug("parent : " + parentIssueId)
// Compteur du nombre TOTAL d'issues enfant du PARENT
def allChildrenIssue = 0
// Comteur du nombre d'issues enfant DEJA passées en DONE
def allChildrenDone = 0
// On itère les enfants du PARENT
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(parentIssueId);
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
// On récupère l'issue enfant ...
def linkedIssue = issueLink.getDestinationObject()
// ... puis on stocke son statut
String statusOfTheChild = linkedIssue.status.name;
// On incrémente le compteur d'issues ENFANTS
allChildrenIssue ++
// On incrémente le compteur d'issues enfants déjà DONE
if(statusOfTheChild == "Done"){
allChildrenDone ++
}
}
// Si il y a d'autres tâches qui ne sont pas DONE, cette transition est inaccessible
if (allChildrenIssue != (allChildrenDone + 1)){
passesCondition = false;
}
The problem is the condition isn't working. Logs are showing me i get null for the parentIssueId variable...., can't understand why...
I got the feeling it's almost this but i still miss something !
Thanks by advance!
I fix the problem by changing the way i did the verification.
here is the solution :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
// Allow logging for debug and tracking purposes
import org.apache.log4j.Level
import org.apache.log4j.Logger
// Script code for easy log identification
String scriptCode = "Check all items resolved -"
// Setup the log and leave a message to show what we're doing
Logger logger = log
//logger.setLevel( Level.ERROR )
logger.setLevel( Level.ALL )
logger.debug( "$scriptCode Triggered by $issue.key" )
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
def found = issueLinkManager.getOutwardLinks(issue.id).any{
it?.destinationObject?.getResolution() == (null || "Unresolved")
}
if (found){
logger.debug( "GetResolution empty found" )
passesCondition = false
} else {
logger.debug( "GetResolution no empty found" )
passesCondition = true
}
One more thing, i'm also open to other solutions that can fix this. I try JQL condition but i wasn't able to find exactlywhat i want
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.