Set a custom field to its default value in a transition

Philippe Cadieux January 16, 2018

Hi,

I would like to set a custom field back to it's default value when an issue is re-opened. I know how to set a value during a transition and even how to get the current value via a Groovy script but I can't seem to find a way to find the field's default value? Right now we have the default value "hard coded" into a post function but the field's default value changes on a monthly basis so I'd like to be able to update the default value in the Custom Field configuration without having to go and also change all my Post Functions. 

 

Please note that while we have JIRA Misc Workflow Extensions, we don't have Script Runner. 

 

Thanks for the help!

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 16, 2018

Hi,

finding the default value of a field in Jira is actually overly complicated. It really depends on the type of custom field. If you tell me which custom field type it is, I might be able to provide the appropriate code.

Philippe Cadieux January 16, 2018

 

Sorry, I knew I forgot something in my original post! The Custom Field is a "Select List (single choice)"

 

Thanks

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 17, 2018

You can use the following script:

import com.atlassian.jira.component.ComponentAccessor
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("select")
FieldConfig relevantConfig = customField.getRelevantConfig(issue);
customField.getCustomFieldType().getDefaultValue(relevantConfig)
Like Silvian Iosub likes this
Philippe Cadieux January 17, 2018

That worked perfectly, thanks a lot!

jordan March 31, 2020

I need to do the same thing with both a Multi Line Text Field and a Multiple User Picker.  There are multiple Contexts in the Jira instance, too.

 

Thanks.

Suggest an answer

Log in or Sign up to answer