How do I reference custom fields in a ScriptRunner simple scripted validator? Edited

In a JIRA workflow, I would only like to a require a Custom Field called "Changelist #" when the Resolution Type of the issue is "Fixed"

I've tried using the following snippet as my condition for my ScriptRunner simple scripted validator, but it is not functioning as intended:

issue.resolutionObject?.name != "Fixed" || cfValues['Changelist #']

 

I'm using this documentation, but have a feeling I'm not referencing my Custom Field correctly.

https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/validators/simple-scripted-validators.html

 

Any help is appreciated!

2 answers

1 accepted

0 votes
Rian Spivak Community Champion Nov 17, 2017

The logic seems valid. Breaking it down:

You want the entire statement to be true in these two cases, where the resolution ISN'T "Fixed" OR where the resolution IS "Fixed" AND "Changelist #" is populated. So the code for that would be

issue.resolutionObject?name != "Fixed" || (issue.resolutionObject?name == "Fixed" && cfValues['Changelist #'] != "")

which reduces down to what you have above. It uses what the script runner documentation you linked to references as "Groovy Truth"

However, if you wanted to see if someone actually enters something in the "Changelist #" field during the actual transition, you have to do something additional to check for that. Something involving using the issue and originalIssue objects along with getting the custom field value in a different way.

Joshua Yamdogo Community Champion Nov 17, 2017

For Simple Scripted Conditions, cfValues['Field Name'] will check whether someone enters something in the field during the transition. It gets the contents of the field that is currently present on the form. 

0 votes
Joshua Yamdogo Community Champion Nov 17, 2017

Hi Jordan,

Your condition looks fine, but could you clarify your workflow? Does the issue already have a resolution of "Fixed" and you want to add a validator for when someone changes the resolution to something else FROM "Fixed"? Or this is validator for when someone changes the resolution from something TO "Fixed"? I assume it's the latter.

cfValues['Field Name'] should be the correct way to check whether a field is empty or not. Have you remembered to publish your workflow after adding this validator? Have you ensured that the field 'Changelist #' is actually completely empty?

It turns out that the name of the "Fixed" resolution differed slightly between my development project for prototyping workflows and actual project. The statement I wrote works correctly. Thank you for the help!

Joshua Yamdogo Community Champion Nov 20, 2017

Hi Jordan,

That sounds frustrating! Glad to hear you have it working now.

Thanks for using ScriptRunner!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,095 views 13 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot