Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted Validator- check if subtasks from issues in epic are "Done"

Ian Balas September 16, 2021

This post relates to my previous Set Linked Issue dependencies via post-function with JMWE or Scriptrunner  post.

I originally wanted to figure out how to set issue link dependencies automatically with create/clone issue(s) post-functions. How it works is I create an epic, and the epic's post-functions fire off and create a series of nested issues, each of which also auto-generate sub-tasks of their own, as shown below:

Screen Shot 2021-09-14 at 5.14.35 PM.png

I originally wanted to set the 'Linked Issues' field for each issue created in the series to follow what's depicted in the spreadsheet below (see column F):

Screen Shot 2021-09-14 at 5.49.09 PM.png

But I figured an easier workaround would be to set validators for the sub-tasks, ensuring that whatever sub-task is blocking them gets completed first. For instance, I was able to make it work for the UX Wireframes and Technical Assessment sub-tasks by enabling this scripted condition:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

if ((! issue.isSubTask()) && (issue.issueType.name != "UX Wireframes" || issue.issueType.name != "Technical Assessment")) {
return true
}

def parent = issue.parentObject
parent.subTaskObjects.any { subtask ->
subtask.issueType.name == 'Write the PRD' && subtask.status.name == 'Done'
}

This works as expected, for when I tried closing out a UX Wireframes sub-task without closing the Write the PRD subtask first, the transition failed (as expected) with the error message "The 'Write the PRD' Sub-task must be done first before closing this out." in red:

 

Screen Shot 2021-09-16 at 1.28.32 PM.png

Now, what I want to do is check the status(es) of subtasks from another parent issue, other than the parent of the subtask of which this validator is running on. In this instance, if I want to close the Finalize/Scope PRD sub-task (nested in the Define Requirements story), the Write Test Cases and Estimate Implementation Tasks sub-tasks (nested in the Solutions Analysis story) have to be marked 'Done' first. I tried the same scripted validator approach, but got stuck when I realized that I had to pull from a different issue object other than the current sub-task or its parent issue. This is what I tried:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager


if ((! issue.isSubTask()) && (issue.issueType.name != "Finalize/Scope PRD")) {
return true
}

IssueManager issueManager = ComponentAccessor.getIssueManager()

def solutionsAnalysisIssueInParentsEpic =
issueManager.getIssueIdsForProject(issue.projectObject.id)
.sort()
.reverse()
.find {
def foundIssue = issueManager.getIssueObject(it)
return foundIssue.issueType.name == "Solutions Analysis"
}

solutionsAnalysisIssueInParentsEpic.subTaskObjects.any { subtask ->
(subtask.issueType.name == 'Write Test Cases' && subtask.status.name == 'Done') &&
(subtask.issueType.name == 'Estimate Implementation Tasks' && subtask.status.name == 'Done')
}

How could I fix the snippet above to check the statuses of subtasks of an issue that's not the current sub-task's parent issue?

Any help would be highly appreciated. Above all, I hope this makes sense. Let me know if any of this is not clear.

0 answers

Suggest an answer

Log in or Sign up to answer