Get the Default Value of a Custom Field
Abstract
This code snippet gets the default value of a specific custom field.
Logic
Access the custom field by its name, get its relevant configuration for the current issue and then get its default value.
Snippet
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager;
CustomField customField = customFieldManager.getCustomFieldObjectByName("<Custom field name>")
FieldConfig relevantConfig = customField.getRelevantConfig(issue);
customField.getCustomFieldType().getDefaultValue(relevantConfig)
Placeholders
Placeholder | Description | Example |
---|---|---|
| Name of the custom field |
|
Examples
The outcome of the code snippet is a String
or an array of Strings (String[])
or an object or a collection of objects which depends on the custom field specified. You could use this code for example to: Set a checkboxes field value to its default value using one of the Set field value post-functions when the default value of the field changes often.