Bulk Update the Value of a Custom Field on Jira Issues

Overview

Use this script in the Script Console to update the value of a custom text field for all issues returned by a query.

Example

I have a project with many issues. I need to change the custom field value for all the issues in this project. With this script, I can easily bulk change all of these issues automatically.

Good to Know

  • (Cloud) Run as an admin user or as "ScriptRunner Add-On User" to make sure permissions to update are granted.

Requirements

    
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.search.SearchProvider import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.jql.parser.JqlQueryParser import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.issue.search.SearchQuery // issues returned from that JQL will get altered final String searchQuery = "project = SSPA" // the name of the custom field to alter final String customFieldName = "TextFieldA" // the new value to set final String newValue = "Love Groovy" def customField = ComponentAccessor.customFieldManager.customFieldObjects.findByName(customFieldName) assert customField : "Could not find custom field with name $customFieldName" def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser) def searchProvider = ComponentAccessor.getComponent(SearchProvider) def issueManager = ComponentAccessor.issueManager def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser def query = jqlQueryParser.parseQuery(searchQuery) def searchResults = searchProvider.search(SearchQuery.create(query, user), PagerFilter.unlimitedFilter) searchResults.results.each { def issue = issueManager.getIssueObject(it.docId) customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder()) }
Discovered an issue? Report it here

Suggested for you

Appears in these Collections