You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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.