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

How can I get this simple scripted validator to work?

Edited

G'evening,

I have a simple scripted validator set on one of the transitions in my Story workflow. The goal is to prevent the transition if the Story has the "Type" custom field set to "Software" and the "Test Criteria" custom field is blank. Here's what I got which isn't working.

(cfValues['Type'] != 'Software') || (cfValues['Type'] == 'Software' && cfValues['Test Criteria'])

 

1 answer

0 votes

If your "Type" custom field is a select of some kind, you might want to try it like this:

def typeValue = (cfValues['Type'].value
(typeValue != 'Software') || (typeValue == 'Software' && cfValues['Test Criteria'])

That's because the cfValues data type will depend on the selected field. If it returns an "Option" object, then you have to look inside that object to get the text value (as oposed to the option Id).

Also, a bit of free advice... you might want to consider renaming that "Type" field to something more specific. Since "type" is a keword shortcut in JQL meaning the same as "issueType".

Now, if you try to write a JQL like

type = story 

You may have inconsistent behaviour, or you will be forced to use the "cf[12345] = Software." format.

Final version:

import org.apache.log4j.Level
import org.apache.log4j.LogManager
import org.apache.log4j.Logger

Logger rootLogger = LogManager.rootLogger
rootLogger.level = Level.INFO

if (issue.issueType.name == 'Story') {
def typeValue = cfValues['Type']?.value
def testCriteria = cfValues['Test Criteria']?.value
log.info("Type: ${typeValue}, Test Criteria: ${testCriteria as Boolean}")

(typeValue != 'Software') || (typeValue == 'Software' && testCriteria)
} else {
true

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...

138 views 1 2
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