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

This widget could not be displayed.

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.

This widget could not be displayed.

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 widget could not be displayed.

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?

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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
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 16 hours ago 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...

42 views 1 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