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
For your other subtasks are you sure the transitions are valid? Basically in your workflow is there a global transition or transition to cancel from all other states to cancelled/rejected?
I can see there are log.debug lines in your code. If you look in your log then most likely you will find a reason why other subtasks are not transitioning.
Ravi
Thanks for response, Yes at any stage you can cancel the issue, and that is a global transition which we have. my ask here is on one stage where the sub task gets created, post the sub task gets created at any point if you may wish to cancel the parent SR, it should canel all the sub task.
I also looked at the log, do not see any error except this "Your Misc Custom Fields app license has an error : EXPIRED
not sure if this could be an issue - but just want to have a view.
Sriram
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.