I have a requirement in JIRA Service Desk, where multiple Sub-tasks need to be created. Once the Parent request is approved and automatically goes to the "In Progress" state, all the Sub-tasks need to go to the "In Progress" state.
For instance, a Service Request is created where
- "Services", a multi select list field contains values - JIRA, Confluence
- "Product category", a cascading select contains value - Standard Laptop >> Linux
here, 2 Sub-tasks for "Services" and "Product category" are successfully being created.
Question:
Now, when the Service Request is approved, it moves to the "In Progress" state. What I want is that, all the Sub-tasks too should move to "In Progress" state once the Service Request is approved and moves to the "In Progress" state. Is this possible at all?
My hosted JIRA version is 17.3.3, and I am using Scriptrunner version 5.5.6.
Can anybody please help me out?
Let me know if any further details are required.
Here's a snippet that does what you asked
1. Make a scriptrunner event which reacts to Generic Events.
2. Put in the code and change the variables
It checks if the latest change is a status change from "To Do" to "In Progress", and if it is, it changes all subtasks which are in "To Do" through a transition in the workflow
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.IssueInputParametersImpl
//Name of the status FROM and TO
def TODONAME = "To Do"
def INPROGRESSNAME = "In Progress"
//ID of the transition the subtask should use to go to start (see workflows)
def TRANSITIONID = 11
//Type of issue it should exclusively work for
def ISSUETYPE = "Task"
if (event.issue.getIssueType().getName() != ISSUETYPE)
return;
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def issueService = ComponentAccessor.getIssueService()
def issue = event.issue
def changes = changeHistoryManager.getChangeHistories(issue)
def user = changes.get(changes.size() - 1).getAuthorObject()
//Get latest change and check all the change item beans
for (ChangeItemBean changeItemBean : changes.get(changes.size() - 1).getChangeItemBeans()) {
//Check if latest history change contains a status change from TO DO to IN PROGRESS
if (changeItemBean.getField() == "status" &&
changeItemBean.getFromString() == TODONAME &&
changeItemBean.getToString() == INPROGRESSNAME) {
//Update all subtasks via the TRANSITIONID transition
for (Issue subtask : issue.getSubTaskObjects()) {
if (subtask.getStatus().getSimpleStatus().getName() != TODONAME)
continue;
log.warn("Transitioning issue $subtask.key through action $TRANSITIONID")
def transitionValidationResult = issueService.validateTransition(user, subtask.getId(), TRANSITIONID, new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(user, transitionValidationResult)
log.warn(transitionResult.isValid() ? "Transition Succes" : "Transition Not Valid")
} else {
log.warn("The transitionValidation is not valid")
}
}
}
}
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.
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.