Script Runner Behaviours - Conditionally show/hide custom field

L_ PEREIRA April 13, 2024

I'm trying to create a conditional to show/hide a custom field in Jira cloud by Behavior on Script Runner:

Fiels:

- Test in homologation (bolean type)
- Probability (single list type)

Basically:
In the creation screen, if I select "Yes" in the "Test in homologation" field the "Probability" field should appear and if I select "No" the "Probability" field should not appear.

 

Script:

const testHML = getFieldById('customfield_10388');
const probability = getFieldById('customfield_10415');

const testHMLValue = testHML.getValue().value

switch (testHMLValue) {
            case 'Yes':
                probability.setVisible(true);
                break;
            case 'No':
                probability.setVisible(false);
                break;
}

 

But when testing, nothing happens, both fields appear and no behavior to hide the probability field is performed.

This is the code I built from the example used in the Script Runner video:
https://www.youtube.com/watch?v=9MNsjBm9New&ab_channel=ScriptRunner

 

Has anyone also encountered this problem?

 

2 answers

1 accepted

0 votes
Answer accepted
Lina Kuhn April 18, 2024

Hi @L_ PEREIRA ,

As done in an example script here, you may have to detect changed fields in your behavior. Assuming, that testHML is a radio button field , this change may work:

const testHML = getFieldById('customfield_10388');
const probability = getFieldById('customfield_10415');

const changedField = getChangeField();

switch (changedField.getName()) {
  case 'Test in homologation':
switch(changedField.getValue().value) { case 'Yes': probability.setVisible(true); break; case 'No': probability.setVisible(false); break;
}
break; }
 

 

L_ PEREIRA April 19, 2024

Hi Guys,

I just verified that this behavior is not compatible with Jira Service (the way I was trying it).

I reproduced it in a Jira Software project and succeeded!

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 18, 2024

Hi @L_ PEREIRA

Please clarify what type of field you are using for Test in homologation? Is it also a List or a Radio Button?

I am requesting this so I can test it in my environment and see if it can work.

Thank you and Kind regards,

Ram

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events