Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Validator - Validate field from parent

Hi,

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:
issue.parentObject.statusObject.name == "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?

Thanks!

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
TAGS
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

30 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you