I need assistance with a Scriptrunner behavior to hide/show a field based on value of checkbox field.
"Origin of Defect" (checkbox field)
"Origin of Defect: Other" (single line of text field)
My checkbox field "Origin of Defect" contains numerous values including "Other". I want to show and require the "Origin of Defect: Other" field if the "Origin of Defect" field CONTAINS the selection "Other" (ID 12828 in my case). This works perfectly if ONLY "Other" is selected, however if multiple checkboxes are selected it does not work.
How can I update to accept multiple selections and still get desired behavior ?
def od= getFieldByName("Origin of Defect")
def odO = getFieldByName("Origin of Defect: Other")
odO.setHidden(true)
def odValue = od.getFormValue();
if (odValue =="12828") // Other
{
odO.setHidden(false)
odO.setRequired(true)
}
else
{
odO.setHidden(true)
odO.setRequired(false)
}
Hi @Pete P
DOes this script works ?
def od= getFieldByName("Origin of Defect")
def odO = getFieldByName("Origin of Defect: Other")
odO.setHidden(true)
def odValue = od.getFormValue() as List;
if (odValue.contains("12828")) // Other
{
odO.setHidden(false)
odO.setRequired(true)
}
else
{
odO.setHidden(true)
odO.setRequired(false)
}
Regards
Let me check one moment!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes but the one I posted ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Florian Bonniec your code DOES work if MULTIPLE checkboxes are selected, as long as one is "Other" !
But... if only one checkbox ("12828")) // Other is selected, it no longer works - very strange. Thanks for your prompt reply!
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.
And this one ?
def od= getFieldByName("Origin of Defect")
def odO = getFieldByName("Origin of Defect: Other")
odO.setHidden(true)
def odValue = od.getFormValue();
if(odValue instanceof String){
odValue = [odValue]
}
if (odValue.contains("12828")) // Other
{
odO.setHidden(false)
odO.setRequired(true)
}
else
{
odO.setHidden(true)
odO.setRequired(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The issue is that the value returned is a String when there is one value selected but an array if there is multiple values selected.
The script above should transform the String value to an array with one value.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That works PERFECTLY @Florian Bonniec . Thank you for the explanation as well.
It is throwing up a warning but it works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes it's because you did not define odValue so it's consider as an object. We cannot define the type for this as it can be String or Array you can get around by creatin a new variable.
def od= getFieldByName("Origin of Defect")
def odO = getFieldByName("Origin of Defect: Other")
odO.setHidden(true)
def odValue = od.getFormValue();
String[] odValues
if(odValue instanceof String){
odValues = [odValue]
}else{
odValues = odValue
}
if (odValues.contains("12828")) // Other
{
odO.setHidden(false)
odO.setRequired(true)
}
else
{
odO.setHidden(true)
odO.setRequired(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Florian Bonniec , getting another message:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it's a simple warning no ?
You can add "as List" at the end of the line 16
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perfection :)
Many thanks for all your help!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Is there an option to get this to work for the Portal Submission?
To have a checkbox field and if something is selected on the checkbox on the Portal, then another text box field will show
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.