How to query field using Script Runner

I am trying to setup a listener using Script Runner to auto transition a field based on the value of a custom field. The plugin provides the following template:

cfValues['SomeCustomField'] == 'Some Value'

I have tried the following:

cfValues['Field Name'] == 'Yes'

But this isn't working. Any suggestions on how to check the value of a custom field for my condition statement?

6 answers

1 accepted

Accepted Answer
7 votes

Turns out i was making a noobish mistake. This worked for me:

cfValues['Standard Request']?.getValue() == 'Yes'

I needed to add the getValue method in order to do my comparison.

The key question as Thomas says is "what kind of field". You can do

log.warn cfValues['Standard Request']

That will give you the class name, from that you can read the javadoc to see how to get the string value or values, or whatever.

What kind of custom field is this?

If it is a checkbox you could use:

cfValues['Field Name'] != null

Hope this helps,
Thomas

It's a radio button with "Yes" or "No" as options.

This is not working for me when using Select List, as opposed to Radio Buttons. Any ideas?

Can you post what you are using.

cfValues['A Radio Field']?.getValue() == 'Yes'

should work fine.

I am using:

cfValues[‘A Select List Field’]?.getValue() == ‘Yes’

Any ideas why this wouldn't work for a select list?

I guess 'Yes' needed to be written "Yes" or the condition kept failing.

I got this working after reviewing your link. Thanks so much!

Is there a parameter I can add to make the condition specific to a project?

&& issue.projectObject.key == "ABC"

I can't seem to get this to work. Tried using an assertion and it returns 404 page

issue.projectObject.key != "ABC" && cfValues['Customization Issue']?.getValue() == "Yes"


This script accomplishes what I want it to do when the value = Yes. But, when the custom field = No, it also firing the function, when I don't want it to.


Any ideas?

Did you get an answer for radio button ? I'm still looking for...

Thanks,

Any help appreciated

The accepted answer is correct for radio buttons.

Ok, but how do you get the value ? cfValue['Answer'].value ?

Answer o Yes o No

Because, in Jira, I would like then test cfValue['Answer'].value == 'Yes' in order to fasttrack a transition, but it does not work unfortunately...

It should be cfValues (plural)

Use: cfValue['Answer']?.value

Use Admin -> Built-in Scripts -> Condition Tester to make sure that is evaluating to what you expect...

> Ok, but how do you get the value ? cfValue['Answer'].value ?
> Answer o Yes o No

I didn't understand this...

Answer o Yes o No ............. it was an example of the radio button field I have with the values which can be chosen.


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

463 views 7 5
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