How to validate field depending on component selection (simple script validator)?

I have to set up a workflow transistion validation via simple script validator but it does not work. Depending on a value choosen in field "Component/s" another custom field hast be checked if it's empty or not.

I've tried different script strings like:

( 'xy'||( 'Umsystem'&&cfValues['Affected Umsystem-Release']!=null)

Each part of this simple script works as single validation but not in whole. Do you know why?

Additionally, how can I set the codition "component does not contain a certain value"? I've tried this:

result = issue.getComponents().find('Guide-Res') < 1

componentManager.issue.getComponents().find('Umsystem') < 1

issue.getComponents.find('Umsystem Guide-Res') < 1

Thanks for your help! It's very much appreciated!!!

Version of JIRA v4.0.2#472; Plugin Version: 1.7.13

4 answers

1 accepted

4 votes

It should be


because Issue.getComponents returns a Collection. Note the * - the spread-dot operator. This calls getName on every element in the collection, returning a List.

Whether you use brackets or not as in Wolfgang's answer makes no odds, they're optional in groovy unless they make a syntactic difference.

Also the !=null in your question is redundant.

> Additionally, how can I set the codition "component does not contain a certain value"? I've tried this

! issue.components*.name.contains('...')


instead of 'xy'

it worked for me

What i said below is correct, brackets make no difference for the example above, however with the code in the question they may well make a logical difference. If you're not sure whether to use brackets, use them.

It did not work for me on the "create issue" initial transition validation. Anything I'm missing?

Thanks a lot. It works very well!

@Jamie Echlin [Adaptavist]

Having similar issue... I am trying to add conditional in a split workflow a la 

However, it's the JIRA Component/s field I am trying to make conditionally mandatory at Analysis Complete rather than a custom field; per this thread, I added the validator'Policy') to the version of the workflow transition that should make custom field Z mandatory, and it's not making the field mandatory... Ideas?

Can you paste the full script or attach a screenshot?

For the Conditions on the workflow transition that will make the field mandatory:'Policy')

for the conditions on the workflow transition that will not make the field mandatory



These, again, are added as a script workflow function, simple scripted condition, checks script. that's all I've done aside from create a cloned transition for the purpose.



To make the another field mandatory if components has Policyt it would be: !'Policy') || cfValues["Some other field"] The field name in the form is just where the message is shown, it has no bearing other than that. There are several examples here that should help:

Adding ! lets all issues move forward without mandatory field. Removing ! stops all issues from moving forward unless mandatory field populated. Not pulling on Component value. ____________________________________________ Validators (2) Required fields: Analysis Hrs, Bug Source, Complexity, Dev Estimate Hrs, Netsuite CA Classification, QA Estimate Hrs, RCA Categories - BA, Release Notes, Severity — AND Script workflow function : Simple scripted validator : Checks script: !'Policy') || cfValues["Policy_2015"]

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

135 views 1 17
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