Setting Field Defaults
Jira doesn’t make it easy to set defaults for system fields out of the box. Using Behaviours you can set default values for system and custom fields, and, set different defaults depending on the current user’s role level or groups.
Set default values when you want to allow the end user to change them from the initial values, or you want to provide a sensible structure for a multiline text field. Examples of this could be the correct phrasing for a user story or a bug report.
You can also "lock" the field by making it read-only. You could achieve the same result by setting the field in a post-function, however, this would overwrite any value the user had provided and is not very friendly.
Note that there is a longer worked example covering setting a default description in the behaviours overview page. This page is primarily to provide code examples for setting the different types of fields.
Setting System Field Defaults
When setting default values we use an initializer method. We want this code to fire once only, when the form is first loaded. Further, we check the name of the current action and exit the script if the action is anything but Create Issue - i.e. the user has clicked the Create button. You may need to alter this depending on your workflow, alternatively you could
getAction()?.id == 1, to check the action by ID.
The following example covers how to set components, affects versions, and the assignee.
Setting Defaults for Selects etc
The code required to set default options depends whether it’s a single or multi-select. The same example that works for a single select will work for a radio buttons field, likewise you can use the multi-select code to set a multi checkbox field. For "single" fields set a single value, for "multiple" fields use a
Setting Cascading Select values
Cascading selects are similar to the above example, but a bit more involved as they have parent and child options.
The way to set a cascading select value is:
field.setFormValue(["Parent option value", "Child option value"])
where those two numbers are the IDs of the cascading select options.
For example, given parent AAA and child A2 options, this sets them: