We are using the scriptrunner behavior plugin to set the default text of the description (so that the user has a template to fill out) when opening the create issue screen. Everything works as expected, however an issue we are facing is the scenario when a validation error occurs when clicking "Create" in the dialog.
The validation error gets displayed however the description is set to the default text again, losing all previously entered information.
The code we are using is the following:
import com.atlassian.jira.component.ComponentAccessor import static com.atlassian.jira.issue.IssueFieldConstants.* if (getActionName() != "Create Issue") { return } def desc = getFieldById("description") def defaultValue = "SOME DEFAULT VALUE'' desc.setFormValue(defaultValue)
Are you using an Initializer function? If you are, I would instead create a behavior directly on the Description field with a script similar to this:
def desc = getFieldById("description") def defaultValue="Your Default" if(!desc.getValue()) { desc.setFormValue(defaultValue) }
Thanks for the answer, but how do I create a behavior directly on the description field?
I tried this by "Adding" the description field to the behavior and then adding a server side script with the snippet you provided. However this does unfortuantly not work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I figured it out. I forgot to set a condition when this script should be run.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I added a condition that the script should only be run when the workflow step is "Create issue" (the first workflow step in my workflow).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is your validation in the behaviors plugin or in the field configuration? It still did not work for me. I still get my fields reset when validatioin fails during create issue (e.g. missing component, required in field configuration)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Behaviours
def desc = getFieldById("description") def defaultValue = "SOME TEXT HERE" if (!desc.getValue()) { desc.setFormValue(defaultValue) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In this case, user input will be erased if a field is required in the field configuration (but not if set as required in behaviours script):
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def descTemplateField = getFieldById(getFieldChanged())
def desc = getFieldById("description")
def customField = customFieldManager.getCustomFieldObject(descTemplateField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def epicOption = "User Epic"
def optionsMap = options.findAll {
it.value in [epicOption] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
optionsMap.put ("-1", "None")
descTemplateField.setFieldOptions(optionsMap)
def epicTemplate = "Template Text"
if (descTemplateField.getValue() == null ) {
desc.setFormValue("")
}
else if (descTemplateField != null && descTemplateField.getValue() == epicOption) {
desc.setFormValue(epicTemplate)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.