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

Scriptrunner behaviour - Show hide field on select.

Neil Dixon October 26, 2018

Hi 

I have a Yes/No select box that on Yes I want to show 3 fields and on No I want to hide the fields.

scriptrunner: 4.1.3.29

Jira server: 6.4.10

With the script below when I display my ticket the helper text is displayed as expected (the current value in the field is Yes).  However when I change the value to No the helper text is removed but not displayed the fields don't change.

Any help would be appreciated.

Thanks,

Neil

=== script === 

 

log.warn("setting conditionField");
def EARequiredfield = getFieldById("customfield_14819");
def EARequirements = getFieldById("customfield_14821");
def EAStatus = getFieldById("customfield_14822");
def EAComments = getFieldById("customfield_14823");
def EARequired = EARequiredfield.getValue();

if (EARequired == "No"){
EARequiredfield.setHelpText("test: " + EARequired );
}
else {
EARequiredfield.setHelpText("test 1: " + EARequired );
}

EARequired.each { selectVal ->
if (selectVal == "No"){
EARequirements.setHidden(false);
EAStatus.setHidden(false);
EAComments.setHidden(false);
log.warn("source value: " + EARequirements.isHidden());
}
else {
EARequirements.setHidden(true);
EAStatus.setHidden(true);
EAComments.setHidden(true);
}
}

 

 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 26, 2018

Hi @Neil Dixon

at first sight, without running this up on a test system, it looks like you are hiding fields (setHidden(true)) when flag is Yes

is that your intention?

Neil Dixon October 26, 2018

Hi

Thanks no it wasn't my intention. I've changed the if statement and it doesn't make any difference.  Bellow is the updated script.

Neil

log.warn("setting conditionField");
def EARequiredfield = getFieldById("customfield_14819");
def EARequirements = getFieldById("customfield_14821");
def EAStatus = getFieldById("customfield_14822");
def EAComments = getFieldById("customfield_14823");
def EARequired = EARequiredfield.getValue();

if (EARequired == "No"){
EARequiredfield.setHelpText("test: " + EARequired );
}
else {
EARequiredfield.setHelpText("test 1: " + EARequired );
}

EARequired.each { selectVal ->
if (selectVal == "Yes"){
EARequirements.setHidden(false);
EAStatus.setHidden(false);
EAComments.setHidden(false);
log.warn("source value: " + EARequirements.isHidden());
}
else {
EARequirements.setHidden(true);
EAStatus.setHidden(true);
EAComments.setHidden(true);
}
}

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 26, 2018

i'll try this out on my JIRA

does the checkbox have a default value or is none allowed. Might need to check !Yes in both places

Neil Dixon October 26, 2018

I've tried both with and without a default value.

It's a single select box not a checkbox not sure if that makes a difference.

Neil

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 26, 2018

Hi

this works in my system. 

log.warn("setting conditionField");
def EARequiredfield = getFieldById("customfield_10300");
def EARequirements = getFieldById("customfield_10301");

 

def EARequired = EARequiredfield.getValue();
log.warn("10300 " + EARequired)
if (EARequired == "No"){
EARequiredfield.setHelpText("test: " + EARequired );
}
else {
EARequiredfield.setHelpText("test 1: " + EARequired );
}
//EARequired.each { selectVal ->
if (EARequired == "Yes"){
EARequirements.setHidden(false);

log.warn("source value: " + EARequirements.isHidden());
}
else {
EARequirements.setHidden(true);
log.warn("source value: " + EARequirements.isHidden());

//}
}

I changed

EARequired.each { selectVal ->
if (selectVal == "Yes"){

to

if (EARequired == "Yes"){


I think that only works here because there is only one value 

Neil Dixon October 26, 2018

Thanks!!

Worked just as I hoping.

Neil

TAGS
AUG Leaders

Atlassian Community Events