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. :(
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks! after some trial and error I came to the same conclusion! :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.