Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Transition of an issue based to sub-task state with 2 different workflow

Stefano Galati March 9, 2020

Hello everyone,

I would like to change the state of an issue when a sub-task go through its "In progress" state to "Done". One important point is that the issues belong to a workflow while all sub-task belong to a different one.

After some search on the community I tried with this code:

import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;

WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
MutableIssue parent = issue.getParentObject() as MutableIssue

workflowTransitionUtil.setIssue(parent)
workflowTransitionUtil.setAction(241)
if (workflowTransitionUtil.validate()) {
workflowTransitionUtil.progress()
}

that return a simple message error like this

ERROR [workflow.AbstractScriptWorkflowFunction]: Script function failed on issue: NSJ-15, actionId: 161, file: null

Anyone can help me?

Thanks

1 answer

1 accepted

0 votes
Answer accepted
Stefano Galati March 9, 2020

hello,

after few tentatives I decided to use a different approach and I solved my problem.

I add the code below in case someone would to do the same thing

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.MutableIssue

MutableIssue parent = issue.getParentObject() as MutableIssue
Integer actionId = 241

IssueService issueService = ComponentAccessor.getIssueService()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
TransitionOptions transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

IssueService.TransitionValidationResult result = issueService.validateTransition(currentUser,
parent.getId(),
actionId,
issueService.newIssueInputParameters(),
transitionOptions)

if (result.isValid()) {
issueService.transition(currentUser, result)
} else {
log.warn result.getErrorCollection().getErrors()
}

Suggest an answer

Log in or Sign up to answer