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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,409
Community Members
 
Community Events
176
Community Groups

Behaviours: How to make custom field required when I select a specific radio button option?

Version - Behaviours with Jira v8.5.1 

I have been using a Beavhiours script for several months now with great success. It currently shows/hides various fields based on user selections (lists, cascading lists, checkboxes). I want to condition the required/optional condition of a text field based on the value of a radio button.

IS: Text field required status not changing when I make correct radio button selection
SHOULD BE: Text field should become required when I select specific radio button

Goal: Use Adaptavist Behaviours to make textField required when both 1. a radio button (radioField) and 2. a cascading list (listField) meet a certain selection condition.

Here is my sample code in one of the Behaviours "Fields":

// set pointers to custom fields (list, radio button, and text)
def listField = getFieldByName ("My List")
def radioField = getFieldByName ("My Radio")
def textField = getFieldByName ("My Text")

// get cascading list value (parent and child)
String listString = listField.getValue()
// if cascading list matches one of two selections, show the radio button field
if ((listString == "[Parent1, Child1]") || (listString == "[Parent1, Child2]")) {
    radioField.setHidden(false)
} // otherwise, hide the radio button field
else {
    radioField.setHidden(true)
}
// get the value of the radio button field
String radioString = radioField.getValue()
// if both the cascading list and radio button value match specific values, make the text field required
if ((listString == "[Parent1, Child1]") && (radioString == "Radio Option")) {
    textField.setRequired(true)
}
// in all other cases, make the text field optional
else {
    textField.setRequired(false)
}

 

This code works except for making the text field required. I can get the text field to become required with the following steps:
1. Set listString to "[Parent1, Child2]"
2. Set radioString to "Radio Option"
3. Set list string to "[Parent1, Child1]"
In this case, we choose one list option that shows the radio button field but does not meet the conditions for making the text field required ("[Parent1, Child2]"). Then we can set the radio button to the correct option. Then set the list option to the one that meets the 2nd condition of making the text field required ("[Parent1, Child1]").

Given this behavior, it seems like the radio button field value is only being updated when I change the list field selection. But shouldn't it be independent of my list selection?

Additional information:
None of my radio buttons will update their value when I change the selection. I determined this by using log.warn on the radio button value and then checking the print statements in the last several lines of "atlassian-jira.log of the built-in script "View server log files". The radio button stays at its default.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events