Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

"The variable [cfValues] is undeclared"

Zita Bagi
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.
March 2, 2020

Dear Everyone,

I would like to run this short script

cfValues['Radio button field']?.value == "Yes"

in Adaptavist ScriptRunner Behaviours but it doesn't work, the error message is: "The variable [cfValues] is undeclared".

Since I got this from here https://scriptrunner.adaptavist.com/5.0.9/jira/recipes/workflow/validators/simple-scripted-validators.html I don't know what I have to import before the script can be run.

I have

import com.atlassian.jira.issue.customfields.option.Option
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

but that's not enough. With a simple scripted validator the line would work by itself but can someone please tell me how to declare cfValues when it has to be declared?

Thank you in advance!

1 answer

1 accepted

0 votes
Answer accepted
Tansu Akdeniz
Community Champion
March 2, 2020

Hi @Zita Bagi ,

You can use the following script if you work with Behaviours.

def formField = getFieldByName("Radio button field")
String fieldVal = formField.getValue()
if(fieldVal.equals("Yes"){
// do sth
}

Please check this link: https://scriptrunner.adaptavist.com/latest/jira/behaviours-api-quickref.html

Regards

Zita Bagi
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.
March 2, 2020

Hi, thank you, I tried this, but it didn't work. The script doesn't show an error but it doesn't perform the desired validation. I want it to do the validation only if Yes is in the checkbox, but now it validates even without the Yes.

Do you have any suggestions?

Thank you in advance!

03021619Capture.PNG

Zita Bagi
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.
March 2, 2020

Also, if I insert this to the workflow as a simple scripted validator, it doesn't allow the transition even if the option is yes and I enter something in the field which I set as required.

Tansu Akdeniz
Community Champion
March 2, 2020

Hi @Zita Bagi ,

It is a Behaviours code, doesn't work in workflow validators.

First of all, please be sure that fields are added to pop-up screen. If not, it doesn't work. As I understand, you want to make a field required depending on other field. 

Go to behaviors -> Add "... Opportunity2" -> Add custom script. It should work.

def opportunityField = getFieldById(getFieldChanged())
String fieldVal = opportunityField.getValue()
def detailsField = getFieldById("customfield_XXXXX") //CF ID

//Debug purpose
opportunityField.setHelpText("Val: "+fieldVal)

if(fieldVal.equals("Yes"){
detailsField.setRequired(true)
}else{
detailsField.setRequired(false)
}

You can use field.setHelpText() method step-by-step in order to find the problem.

Regards

Like Zita Bagi likes this
Zita Bagi
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.
March 2, 2020

Thanks, this worked! Thank you very much for taking the time, I appreciate it!

Tansu Akdeniz
Community Champion
March 2, 2020

You are welcome @Zita Bagi , happy to hear that!

Like Zita Bagi likes this

Suggest an answer

Log in or Sign up to answer