Forums

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

validator for closed sub-tasks of a specific type (scriptrunner)

Janice Castro
Contributor
September 16, 2022

we are using scriptrunner and I am a newbie to jira expressions. I have been trying to figure out how to restrict the transition using Validators for a specific issue sub-task type.

I would like all "defect sub-tasks" to close prior to moving to the next status.

I started with the example from adaptivist which works:

 issue.subtasks.filter(subtask => subtask.status.name != 'Done').length == 0

 

 but I don't know how to modify it so that both status AND issue type are being checked. the parent issue can have other normal sub-tasks that are not of type "defect"

 issue.subtasks.filter(subtask => subtask.issuetype.name == 'Defect' && subtask.status.name != 'Done').length == 0

 

The error I get goes like this:

FALSE

An error occurred. Anything other than a true result is considered false, so the transition would not be allowed.

View Results

Evaluation failed: "subtask.issuetype" - Unrecognized property of `subtask`: "issuetype" ('issuetype'). Available properties of type 'Issue' are: 'assignee', 'attachments', 'changelogs', 'closedSprints', 'color', 'com.herocoders.plugins.jira.issuechecklist-free__checklist-text-view-only', 'com.herocoders.plugins.jira.issuechecklist-free__issue-checklist-progress-field', 'com.herocoders.plugins.jira.issuechecklist-free__issue-checklist-progress-percent-field',.... yada yada yada

 

I have been unsuccessful in trying to find any tutorials for beginners. :(

 

2 answers

1 accepted

3 votes
Answer accepted
Janice Castro
Contributor
September 18, 2022

with a significant amount of trial and error, I finally found the syntax that worked -- I think it was because issueType needed to have a capital T

issue.subtasks.filter(subtask => subtask.status.name != 'Done' && subtask.issueType.name == 'Defect').length == 0
0 votes
Maxime Lefebvre _Okapya_
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.
September 16, 2022

Hi Janice,

The code you have provided is written in JavaScript but ScriptRunner runs Groovy Script (Java). I am not sure exactly how you made the first example work, it doesn't seem to be valid syntax when using it in a script.

If you are using the Workflow Validator named "Custom script validator", here's what you would put in there:

import com.opensymphony.workflow.InvalidInputException;

if (issue.getSubTaskObjects().any { subtask -> subtask.getIssueType().getName() == 'Defect' && subtask.getStatus().getName() != 'Done' }) {
throw new InvalidInputException("All subtasks need to be 'Done'!");
}

 Have a nice day!

Janice Castro
Contributor
September 18, 2022

hi -- I don't think this will work for validators as the required output is only either True or False. I think this code is for Conditions.

The example I used was adapted from their documentation: https://scriptrunner-docs.connect.adaptavist.com/jiracloud/validators.html (scroll to the Sub-tasks Must be in Progress example)

According to this, Validators work with Jira Expressions that evaluate to True or False.

Maxime Lefebvre _Okapya_
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.
September 18, 2022

Hey Janice,

Thank you for the clarifications.

I'm sorry I've missed the part where you are on Cloud, my solution was for ScriptRunner Server / Data Center.

The objects you manipulate in your JavaScript script are Jira Expressions.

If you take a look at the documentation, the issue type property is named issueType and not issuetype (notice the uppercase T).

Simply try:

issue.subtasks.filter(subtask => subtask.issueType.name == 'Defect' && subtask.status.name != 'Done').length == 0

Kind regards 

Janice Castro
Contributor
September 18, 2022

thanks! after some trial and error I came to the same conclusion! :D 

Like Madalina Mutihac likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events