Hi everybody,
i have a workflow for parent issues and a workflow for sub tasks. Now, I would like to trigger that all sub task (of the parent issue) will automatically be set to "cancelled" if the parent issue is manually transitioned to "cancelled" (the status "cancelled" already exists in both workflows).
I´ve already tried some groovy scripts to solve the problem, but obviously my groovy skills aren´t good enough.
Can somebody give me a code example to realize this automation? Where do i have to integrate the post function; in the parent issue or the sub task workflow?
Thank you in advance for your support.
Best regards
Dennis
Hello @Dennis S_
What is your jira version? Question mentioned by @Daniel Yelamos [Adaptavist] have some deprecated methods and may not work on lastest versions.
Here is another code example, without deprecated method:
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue
import org.apache.commons.lang3.StringUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory;
Logger log = LoggerFactory.getLogger("Subtask transition script")
//def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("RFA-467")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
Collection<Issue> subTasks = issue.getSubTaskObjects()
log.error("Found {} subtasks of <{}> issue, starting transitions", subTasks.size(), issue.getKey())
if (subTaskManager.subTasksEnabled && !subTasks.empty)
{
IssueService issueService = ComponentAccessor.getIssueService()
CommentManager commentManager = ComponentAccessor.getCommentManager()
String comment = "Moving to *new status* status as a result of the *this transition* action being applied to the parent.";
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
TransitionOptions transitionOptions = new TransitionOptions.Builder().skipConditions().skipPermissions().skipValidators().build()
subTasks.each {it ->
log.error("Try to transition subtask <{}>", it.getKey())
// In validateTransition method you should write transtion id, in this example 21
IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(user, it.getId(), 21, issueInputParameters, transitionOptions)
if (transitionValidationResult.isValid()){
IssueService.IssueResult issueResult = issueService.transition(user, transitionValidationResult)
if (!issueResult.isValid()){
String cause = StringUtils.join(issueResult.getErrorCollection().getErrorMessages(), "/")
log.error("Transition errors: {}", cause)
}
else{
log.error("transition issue <{}>, finished with result <{}>, adding comment", it.getKey(), issueResult.isValid())
commentManager.create(it, user, comment, true);
}
}
else{
String cause = StringUtils.join(transitionValidationResult.getErrorCollection().getErrorMessages(), "/")
log.error("Transition Validation errors: {}", cause)
}
}
}
That is indeed a better way of doing it. Thanks Mark!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Markov, Hi @Daniel Yelamos [Adaptavist],
thanks a lot for your prompt reply.
Looks like an appropriate solution. I have not yet had an opportunity to try it, but I will inform you as soon as possible (probably tomorrow).
Best regards
Dennis
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.
Hi Denis.
This question has already been answered here:
It is very old though. Is it good enough to help you?
Cheers!
DY
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.