I have a behavior that enters a bug template into the description field of the issue when it is of type "Bug". However, I want to avoid having people lose information if they go back and change the issue type to Bug after entering information.
STR Example:
- Click "Create", create issue screen defaults to the current project, Task
- Enter information including a description.
- Realize this is a bug, switches from issue type Task to issue type Bug.
- Behavior kicks in and replaces the description with the bug template.
I'm checking for a previously filled in form field (using getValue) but the value is returning null always. Is there a different method I should be using?
Code:
import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.*
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
if (getActionName() != "Create") {
return // not the initial action, so don't set default values
}
def templateValue = """*Device / OS:*
*Test Account:*
*Precondition:*
*Steps to Reproduce:*
#
#
#
*Expected Result:*
*Observed Result:*
*Reproducibility:*"""
def descriptionField = getFieldById(DESCRIPTION)
def previousValue = (descriptionField.getValue() as String)?.trim();
if(previousValue == null || previousValue?.equals(templateValue)) {
previousValue = "";
} else if(previousValue) {
previousValue += "\n\n";
}
descriptionField.setFormValue(previousValue + templateValue)