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!
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, this worked! Thank you very much for taking the time, I appreciate it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.