Hello Everyone,
I have created a post function called "Cancel Subtask" and has a groovy script to it. I have multiple sub task associated with parent task, when i cancelled my parent task, only the first sub task associated with parent task is getting cancelled and the other subtask remain the same, doesnt get cancelled. Any has a clue has to why that happens and have solution to cancell all sub task?
Here is my script running for reference
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.component.ComponentAccessor;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.util.ImportUtils
Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
// Get Admin
UserUtil userutil = (UserUtil) ComponentAccessor.getComponentOfType(UserUtil.class);
Collection<ApplicationUser> users = userutil.getJiraAdministrators();
CommentManager commentManager = ComponentAccessor.getCommentManager();
ApplicationUser adminUser = users.getAt(0);
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil)JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects()
def issueService = ComponentAccessor.getIssueService();
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
/*
workflowTransitionUtil.setUsername(currentUser);
workflowTransitionUtil.setAction (7) // 5 == RESOLVE ISSUE
*/
int actionId = 0;
if (it.statusObject.name == "Open") {
actionId = 71
} else if (it.statusObject.name == "In Progress") {
actionId = 91
} else if (it.statusObject.name == "Completed") {
actionId = 101
} else if (it.statusObject.name == "Rejected") {
actionId = 81
}
if (actionId != 0) {
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
//setResolutionId("10004") // resolution of "Fixed"
setComment("This subtask is cancelled as a result of the *Withdraw* action being applied to the parent.")
setSkipScreenCheck(true)
}
// validate and transition subtask
def validationResult = issueService.validateTransition(adminUser, it.id, actionId, issueInputParameters)
if (validationResult.isValid()) {
def issueResult = issueService.transition(adminUser, validationResult)
if (!issueResult.isValid()) {
log.debug("Failed to transition subtask ${it.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.debug("Could not transition subtask ${it.key}, errors: ${validationResult.errorCollection}")
}
}
}
}
Regards
Sriram S