Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

ScriptRunner Validator - Validate field from parent


I'm trying to add a workflow validator for a sub-task that must look at a field from the parent and only allow the transition if a certain value is selected from a custom single select list field.

In order to accomplish this I was trying to use ScriptRunner's Simple scripted validator by trying to get the value from the sub-task parent (which is a Task issue type) but I can't seem to make it work.

It would be easy for example, to know the status of the parent ticket by doing this: == "Open"

I couldn't, however, find find a way to get the value of a custom field from the parent in order to validate that.

Please help.

Thank you!


1 answer

1 accepted

0 votes
Answer accepted

To access the parent issue from a simple scripted customfield, you have to use the full api, you can't use cfValues["fieldName"] shortcut.

For example:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def cfm = ComponentAccessor.customFieldManager
def cfId = 10200 //id of the customfield you want to get values from
def cf = cfm.getCustomFieldObject(cfId)
def parentOption = issue.parentObject.getCustomFieldValue(cf) as Option
def parentValue = parentOption.value

Thanks, @Peter-Dave Sheehan !

This is great but how do I actually add the validation to ensure parentValue has the value that is needed inside of the workflow validator?

Should I just add:

parentValue == "XYZ" at the end?

And is there a way to display a message to the user in case the validation fails?


Yes, terminate the simple scripted validator with a true/false statement to indicate whether the validation passes or fails.

A true value means the validation passed and no message is displayed.

A false value mean the validation failed and the Error Message you configure in the Simple Scripted Validator form (below the condition script box) will be displayed to the users.

Leave the field parameter empty. This will cause the error message to appear at the top of the form.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

189 views 1 6
Read article

Atlassian Community Events