We're using JIRA Software 7.3.1. We have Adaptavist ScriptRunner (5.0.4). I've seen questions posted that sound earily similar to this, but haven't been able to get far with them. (I did cause our server to hang after one attempt though.) I'm a total scripting newbie and a JIRA near-newbie. I'm afraid I need a For Dummies version of this.
The two things that've been asked of me are:
When an issue is transitioned to "Done," transition all of its Subtasks to "Done."
When an issue is transitioned to "In Progress," transition the subtasks with the same Assignee as the parent issue to "In Progress."
Hi Todd,
You can accomplish this by using post-functions in ScriptRunner. For your first problem of transitioning an issue's subtasks to "Done" whenever the issue is transitioned to done, you'll need to add a script post-function on the transition step to Done. The following script will transition all of the subtasks. You'll need to replace the number for workflowActionId to the ID of your transition, which you can easily find on the text view of your workflow in JIRA.
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def Issue issue = issue def workflowActionId = 2 //replace with your workflow step ID def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def adminUser = ComponentAccessor.userUtil.getUser(currentUser.name) def IssueService issueService = ComponentAccessor.issueService issue.subTaskObjects.each { def TransitionValidationResult validationResult = issueService.validateTransition(adminUser, it.id, workflowActionId, issueService.newIssueInputParameters()) if (validationResult.valid) { issueService.transition(adminUser, validationResult) } }
For the second problem, you'll repeat the same steps as the first problem by adding another script post-function to the In Progress transition. However, you'll just need to modify the script to check to see if subtask assignee matches parent assignee (it.assignee == issue.assignee).
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def Issue issue = issue def workflowActionId = 2 //replace with your workflow step ID def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def adminUser = ComponentAccessor.userUtil.getUser(currentUser.name) def IssueService issueService = ComponentAccessor.issueService issue.subTaskObjects.each { if (it.assignee == issue.assignee) { def TransitionValidationResult validationResult = issueService.validateTransition(adminUser, it.id, workflowActionId, issueService.newIssueInputParameters()) if (validationResult.valid) { issueService.transition(adminUser, validationResult) } } }
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.