How to make a behaviour work on Edit screen but not when the Edit dialog opens?

Samuel Lagos
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 17, 2023

Hello,

 

I'm working in a new issue type which has two fields (input required). In this context, I'll call them field A and field B.

Both fields were created using ScriptRunner plugin and both of them are Database pickers.

Field B will run an SQL query using the value which was provided in field A and to avoid unwanted results, I've created a behaviour.

This behaviour will make field B as a read-only field in the Initialiser script, since the value for field B should only be selected after field A value is picked.

Also, I've added a script for field A which will clear the value for field B and make it editable if the value for field A value is different than null. If the field A value is equal to null, this script will also clear the field B and make it read-only.

 

This is working as expected in the Create issue action, however I've found an unexpected result while trying to Edit the issue.

When the Edit dialog shows up, the field A has the previously selected value but field B is null.

I suppose this happens due to the fact that once the Edit dialog appears the field A is mapped with the value given earlier and the behaviour is triggered because the plugin detects that the field A value was changed.

 

Is there a way to make the behaviour trigger only when the field is clicked on and make it so the behaviour is not triggered when the Edit dialog shows up?

For reference, I'm sharing the script for field A below:

 

def fieldB = getFieldByName('Field B')
def currentValue = getFieldById(getFieldChanged())
String auxValue = currentValue.getValue() as String
switch (auxValue){
   case {auxValue != null && auxValue != ""}:
   fieldB.setFormValue(null)
   fieldB.setReadOnly(false)
   break
   case {auxValue == null || auxValue == ""}:
   fieldB.setFormValue(null)
   fieldB.setReadOnly(true)
   break
}
All ideas are welcome. Thanks in advance for your feedback.

 

0 answers

Suggest an answer

Log in or Sign up to answer