Script Runner(validate) check if there is a particular version defined in a multiselect custom field of versions

I'm a "C/perl with C++ from 15 years ago" guy but I'm slowly picking up Java/Groovy syntax on the side so any help would be appreciated.

I reviewed Jamie's page: https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts and tried various formats:

--> cfValues['Planned For'][0] == "main"
--> cfValues['Planned For'].contains("main")
--> cfValues['Planned For']*.value.contains("main")
--> cfValues['Planned For']?.value.contains("main")

Now I tried to determine what I have:
assert cfValues['Planned For'] == "main"
| | |
| [main] false
[Customer:null, Planned For:[main], ...]
So 'Planned For' is an array but lets confirm:
assert cfValues['Planned For'].class == "main"
| | | |
| [main] | false
| class java.util.ArrayList
[Customer:null, Planned For:[main], ...]
What are the elements of the array?
assert cfValues['Planned For'][0].class == "main"
| | | |
| [main] | false
| class com.atlassian.jira.project.version.VersionImpl
[Customer:null, Planned For:[main], ...]
As suspected, I have an array of version objects that I'm trying to compare to string. How can I convert that array of version objects to strings or convert my compare string to a version object? Or what?

2 answers

1 accepted

This widget could not be displayed.

After much head banging for checking a custom field(Planned For) of Versions

Here's my condition of a validator where

if Manager then allow
else if Planned For is null then allow
else if Planned For only equals "main" version then allow
else if Planned For only equals "trunk" version then allow
else fails

isUserMemberOfRole('Managers') || cfValues['Planned For'] == null || cfValues['Planned For']*.getName() == ["main"] || cfValues['Planned For']*.getName() == ["trunk"]

or can use the contains method if one of the multiple version is set to xxxx. i.e. "main"
cfValues['Planned For']*.getName().contains("main")

This widget could not be displayed.

Great, previewing the question really doesn't help with formatting. ;-)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

146 views 2 0
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