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

Scriptrunner behaviour - Show hide field on select.

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

0 votes
Answer accepted
tom lister Community Leader Oct 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?

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 Oct 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

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 Oct 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 

Thanks!!

Worked just as I hoping.

Neil

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

55 views 0 0
View question

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