Multiple Sub task does not cancel when parent task is cancelled

Sriram Subramanian May 30, 2020

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 

1 answer

0 votes
Ravi Sagar _Sparxsys_
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.
May 30, 2020

Hi @Sriram Subramanian 

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

Sriram Subramanian June 4, 2020

@Ravi Sagar _Sparxsys_ 

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 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events