Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Selecting Checkbox field option to show Date Field


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

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Jeroen Poismans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 22, 2020

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

TAGS
AUG Leaders

Atlassian Community Events