Forums

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

Help with Scriptrunner - Parent issue not transitioning when sub-task transitions

Alex Cumberland
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.
March 2, 2021

ScriptRunner 6.18.0 

Jira Server 8.13.1

The logs show no issues and displays the values that I expect but the parent stays in the "Open" status. 

The sub-task and parents use the same workflow.  The transition that I am trying for the parent is "Start Progress" (transition id = 4) which would put it in status "In Progress" (step id = 3) from "Open" or "Reopened" status.

I am using the following script that is the last step in the post-functions:

import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.workflow.TransitionOptions;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.project.Project;

// Logging Imports
import org.apache.log4j.Level
import org.apache.log4j.Logger

log = Logger.getLogger("console")
log.setLevel(Level.DEBUG)

def Project project = issue.getProjectObject()

Integer actionID = 4; // Transition ID value

log.debug "project key: " + project.key;
log.debug "issue key: " + issue.key;
log.debug "issue Type: " + issue.issueType.name;

// Only want to perform for sub-tasks in the OK Project
if (project.key == "OK" && issue.issueType.name == "Sub-task") {

IssueService issueService = ComponentAccessor.getIssueService();

// Get the userID that is logged in currently
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

// Get the parent issue object
MutableIssue parent = issue.getParentObject() as MutableIssue

// Check the status of the parent object
def isValidSubTaskStatus = parent.status?.name in ['Open', 'Reopened']

// If the parent status is valid, then we want to transition the parent
if (isValidSubTaskStatus) {
TransitionOptions transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

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

}

}

 

1 answer

1 accepted

1 vote
Answer accepted
Alex Cumberland
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.
March 2, 2021

Figured out the issue and was a real self head smack moment.

 

The script is fine except it does not have a step to do the actual transition.

 

Needs the following Code after the Validate Transition step:

 

if (result.isValid()) {
issueService.transition(currentUser, result);
}

Doing this will then actually fire the transition on the parent. 

Suggest an answer

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

Atlassian Community Events