How to query field using Script Runner

Cesar Covarrubias September 25, 2012

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

8 votes
Answer accepted
Cesar Covarrubias September 26, 2012

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2012

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.

1 vote
Kathryn Allison October 22, 2013

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 22, 2013

Can you post what you are using.

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

should work fine.

Kathryn Allison October 22, 2013

I am using:

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

Kathryn Allison November 3, 2013

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 3, 2013
Kathryn Allison November 3, 2013

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

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

Kathryn Allison November 4, 2013

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013

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

Kathryn Allison December 19, 2013

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

Kathryn Allison February 23, 2014

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?

Kathryn Allison February 24, 2014
1 vote
Thomas Heidenreich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2012

What kind of custom field is this?

If it is a checkbox you could use:

cfValues['Field Name'] != null

Hope this helps,
Thomas

Cesar Covarrubias September 26, 2012

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

0 votes
Christophe Leite August 21, 2013

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


0 votes
Christophe Leite August 21, 2013

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2013

It should be cfValues (plural)

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2013

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

0 votes
Christophe Leite August 20, 2013

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

Thanks,

Any help appreciated

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2013

The accepted answer is correct for radio buttons.

Like System Admin likes this

Suggest an answer

Log in or Sign up to answer