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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

102 views 1 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you