Hi All,
I have a checkbox field call ENV with the values = NonProd, Stage, Prod.
If anyone selected Prod or Stage from the list we need to make the Security field required.
Here is the code I tried and wont work if I select multiple values in the ENV field, please let me know if anything I can modify in this.
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
def RE = getFieldById("customfield_14200")
def SF = getFieldById("customfield_14217")
def RE1 = RE.value.toString()
if (RE1 in ["Prod" , "Stage"] {
SF.setRequired(true)
}
else {
SF.setRequired(false)
}
Jira Server 7.12.3
Scriptrunner version 5.4.45
TIA!!
I think your issue is that when your checklist has more than one value, you are receiving an array with 2 items instead of an array with one single element.
Can you check if this would work?
def RE = getFieldById("customfield_14200")
def SF = getFieldById("customfield_14217")
if(RE.getValue()*.contains("Prod") || RE.getValue()*.contains("Stage") ){
SF.setRequired(true)
}
else {
SF.setRequired(false)
}
This will set SF as required if the checkbox has Prod or Stage or both selected.
Hi @Italo Qualisoni [e-Core] , thank you, this what I see now on line 5.
If I use the below script, even if I select non prod this script makes the other field required.
def RE = getFieldById("customfield_14200")
def SF = getFieldById("customfield_14217")
def RE1 = RE.value.toString()
if(RE1.contains("Prod") || RE1.contains("Stage") ){
SF.setRequired(true)
SF.setHidden(false)
}
else {
SF.setRequired(false)
SF.setHidden(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the following, when you select one value the instance type is String and when you have more than one value in your checkbox your instance is a List<Option>
import com.atlassian.jira.issue.customfields.option.Option
def RE = getFieldById("customfield_14200")
def SF = getFieldById("customfield_14217")
def options = RE.getValue()
//Single option selected
if(options instanceof String){
if(["Prod","Stage"].contains(options)){
SF.setRequired(true);
}
else{
SF.setRequired(false);
}
}
//Multiple options
else if(options instanceof List<Option> ){
if(options.contains("Prod") || options.contains("Stage") ){
SF.setRequired(true);
}
else{
SF.setRequired(false);
}
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.