Hello ,
I am using the below code to Show and Hide the Target Date Field in my JIRA Server instance using scriptrunner for JIRA . This Target Date will be visible only if option C is selected on the checkbox field -
I have used behaviours and added the checkbox field and written the following code as rhe server side script-
/////////////////////////
def changedCF = getFieldById(getFieldChanged()) // Checkbox A
def custField1 = getFieldById("customfield_11004") // Date Field
boolean isCollection = changedCF.getValue() instanceof Collection
if (isCollection) {
def changedCFValue = changedCF.getValue() as List
if (changedCFValue.contains("A")||changedCFValue.contains("B")||changedCFValue.contains("D")||changedCFValue.contains("E")||changedCFValue.contains("F"))
{
custField1.setHidden(true)
custField1.setFormValue(null)
} else {
custField1.setHidden(false)
}
} else {
def changedCFValue = changedCF.getValue() as String
if (changedCFValue.contains("C")) {
custField1.setHidden(false)
custField1.setFormValue(null)
} else {
custField1.setHidden(true)
}
}
///////////////////
This is not working as per expectation, Can someone please help or direct me to achieve my requirement?
Regards
Priyanka
Hi Priyanka,
I can see why this isn't working. When no option is selected the script might fail. I got it working with fewer code.
First, in your behaviour you should add an initialiser script (at the the top) that sets the default values in load of the Creat screen. Here is the initializer:
def custField1 = getFieldById("customfield_11004") // Date Field
custField1.setHidden(true)
custField1.setFormValue(null)
Then in the field code (which gets executed everytime you change the checkboxes):
def changedCF = getFieldById(getFieldChanged()) // Checkbox A
def custField1 = getFieldById("customfield_11004") // Date Field
def changedCFValue = changedCF.getValue()
if (changedCFValue == null || !changedCFValue.contains("C")) {
custField1.setHidden(true)
} else {
custField1.setHidden(false)
custField1.setFormValue(null)
}
Notice how in the "if" statement there is a null check added. This should now work with no options selected, 1 option, multiple options.
Let me know if this solved it!
Jeroen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.