I'm hoping that someone can help me since my research has not yielded any results.
I have the following requirements:
- When a parentIssue moves to a "Closed" status, all Sub-tasks (not in a currently "Closed" status) are also moved to a "Closed" status.
- Before this move occurs, a popup is displayed that notifies the User that if they continue to move the parentIssue to "Closed", all Sub-tasks will also be Closed and are prompted with two options: Confirm or Cancel.
- I know that ScriptRunner has a built in "Close Parent Issue if Sub-tasks are all closed" prompt like this... and I'm trying to essentially do something similar but in reverse.
- IF User selects "Confirm", THEN the workflow will automatically execute and the code will close all Sub-tasks not in a "Closed" status AND the parentIssue.
- IF User select "Cancel", THEN no action is taken on the parentIssue or the Sub-tasks; all issues remain in their current status.
The code that I have currently written will fulfill Requirement 1...
import com.atlassian.jira.component.ComponentAccessor
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def subTasks = issue.getSubTaskObjects()
subTasks.each {
if (it.statusObject.statusCategory != "Done") {
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setResolutionId("10500") // resolution of "Assumed Complete"
setComment("Sub-task was Closed (with a resolution of 'Assumed Complete') as a result of the Parent Item being Closed.")
setSkipScreenCheck(true)
}
// validate and transition subtask
def validationResult = issueService.validateTransition(user, it.id, 41, issueInputParameters) // transitionId of "Closed" for the Sub-task Workflow
if (validationResult.isValid()) {
def issueResult = issueService.transition(user, validationResult)
if (!issueResult.isValid()) {
log.warn("Failed to transition subtask ${it.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition subtask ${it.key}, errors: ${validationResult.errorCollection}")
}
}
}
And I have a bit of a stop-gap coded where we display a notification that Sub-tasks will be closed (these appear in the upper-right hand corner) but I'd really like to make them actionable rather than notified. Here's the code for that notification...
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
def baseUrl = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)
def issueUrl = "$baseUrl/browse/$issue.key"
UserMessageUtil.success("All 'New' or 'In Progress' Sub-tasks will be moved to a 'Closed' status as a result of this transition." )
But I cannot figure out how to accomplish Requirements 2-4. Has anyone been able to do something like this? Would you mind sharing your tips/tricks/code?
We're currently running on Jira Server 8.9.0 and have JSU and ScriptRunner.
Thanks so much!