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

Actionable Jira Popup on Workflow Transition to Close Sub-tasks of Parent Issue

Shawna Morris
Contributor
December 7, 2020

I'm hoping that someone can help me since my research has not yielded any results. 

I have the following requirements:

  1. When a parentIssue moves to a "Closed" status, all Sub-tasks (not in a currently "Closed" status) are also moved to a "Closed" status. 
  2. 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. 
    1. 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.
  3. 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. 
  4. 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! 

1 answer

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
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.
December 7, 2020

You don't need Scriptrunner to do the screen part (and it couldn't do it anyway).  Plain Jira already does almost all of it off-the-shelf.

Create a workflow that has a "transition screen" on the close transition.  You probably want to put the "resolution" field on it.  For added text, use a Jira Toolkit "message field for edit" on the screen to put your message on the screen.

Shawna Morris
Contributor
December 7, 2020

Thank you, Nic! I had the Toolkit installed already but didn't know about that customField type!

I got one set up, and I have it on my Resolve Issue Screen... but I'm not sure how to set the default value for it - right now, nothing is appearing there (not even the custom field name). 

Thanks so much for the assistance with this one! 

Shawna Morris
Contributor
December 7, 2020

Nevermind! Needed to set the context for it under Default Value! Thanks so much for your assistance! :) 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events