Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Jira DataCenter - ScriptRunner - Auto-transition on subtasks not working

Venkat Krishnamoorthy November 27, 2019

Hello,

I had a ticket open for this in Adaptavist support as well. 

We upgraded our Jira Server and all add-ons including ScriptRunner to Data Center this past weekend. We upgraded ScriptRunner by several versions during this process.

After the migration, our users noticed that the auto-transition of subtasks was working on and off. I am including the script here. This script works at times and other times I dont think it does anything. We added some log warn statements to follow the script execution but nothing is seen in the logs. However, the screen status says it successfully executed for a Jira Issue and we can confirm that in the Payload.

Last night, I spent some more time troubleshooting and it turned out commenting out the following line in the script - "setSkipScreenCheck(true)", fixed the Issue. No comments are being added to the subtasks during the transition but that is less of an Issue now. I understand "setSkipScreenCheck(true)" is to add comment on a ticket when the field is not available on the Edit screen. Not sure why that would affect the transition, though.

 

Here is the original Parent Issue PostFunction script

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.fields.CustomField

CustomField deplInEnv = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Deployed in Environment")

IssueService issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getUserManager().getUserByName("automation")
for(Issue subTask:issue.getSubTaskObjects()) {
if ((subTask.getStatusId() == "10102") && ((!subTask.getCustomFieldValue(deplInEnv)) || (!subTask.getCustomFieldValue(deplInEnv)*.value.contains('Stage')))) {
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setComment("Moving subtasks to ToDo from Parent Deployment Request")
setSkipScreenCheck(true)
}
// validate and transition subtask
def validationResult = issueService.validateTransition(user, subTask.getId(), 111, issueInputParameters)
if (validationResult.isValid()) {
def issueResult = issueService.transition(user, validationResult)
if (! issueResult.isValid()) {
log.warn("Failed to transition subtask ${subTask.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition subtask ${subTask.key}, errors: ${validationResult.errorCollection}")
}
}
}

Thanks
Venkat

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events