I’m creating a new behaviour that does multiple dynamic things.
- Load a map(key/value pairs) from a shared script and sets that as options for a single select field.
- Based on what is chosen, a text field should be updated.
So far, I’ve managed to populate the last based on the map as entered in the script file.
I’ve also managed to trigger an event which enters the switch in my code to decide what to write in the text field. However, the value I’m getting there is always null. Weird thing is, the event is only triggered when following these steps:
- Open the view screen
- Select an option other then the default.
- Select the default option again.
- Event gets triggered, switch statement is checked and value is null.
The initiator script as follows:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import Constants.TemplateDescriptions
@BaseScript FieldBehaviours fieldBehaviours
final listFieldName = 'List'
final descriptionFieldName = 'Description'
def cfManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def listField = getFieldByName(listFieldName)
def descriptionField = getFieldByName(descriptionFieldName)
// Make sure the fields we want to work with are on the form
if (!listField && !descriptionField) {
return
}
listField.setFieldOptions(ListClass.keyValueMap)
And for the Single Select List I have this script:
import java.text.SimpleDateFormat
final listFieldName = 'Description Template List'
final descriptionFieldName = 'Description'
def listField = getFieldByName(listFieldName)
def descriptionField = getFieldByName(descriptionFieldName)
// Make sure the fields we want to work with are on the form
if (!listField && !descriptionField) {
return
}
def date = new Date()
def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
def input = listField.getValue();
switch (input) {
case 'Option 1':
descriptionField.setFormValue('Option 1')
break;
case '-1':
descriptionField.setFormValue('-1')
break;
case 'null':
descriptionField.setFormValue('null');
break;
case -1:
descriptionField.setFormValue('-1 int')
break;
case null:
descriptionField.setFormValue('null null ' + sdf.format(date) + ' input: ' + input);
break;
default:
descriptionField.setFormValue('input:' + input + '\nreverting to default because value is ' + listField.getFormValue() + ' changed value ' + changedField.getValue() + ' value ' + listField.value);
}
I’m wondering whether my desired behaviour is actually possible.