Hi, I see that the following code is available on the Adaptavist library and while it would work for what I am attempting to do, I need some help modifying it.
The idea is to bulk update a custom field called "Created Date & Time" to the created date when a ticker was created.
This field was added as it is used in our Aha Integration so it had to be a custom field.
This is the code:
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 searchQuery = "project = TEST"
// The name of the custom field to alter
final customFieldName = "TextFieldA"
// The new value to set
final newValue = "Love Groovy"
(I assume here is where I would need to change it to make sure that the correct value is added but it would need to be Date&Time and a bit unsure of that?)
// Get the custom field
def customField = ComponentAccessor.customFieldManager.customFieldObjects.findByName(customFieldName)
assert customField : "Could not find custom field with name ${customFieldName}"
// Get some components
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// Perform the JQL search
def query = jqlQueryParser.parseQuery(searchQuery)
def searchResults = searchProvider.search(SearchQuery.create(query, user), PagerFilter.unlimitedFilter)
// Iterate all results to update each issue
searchResults.results.each { documentIssue ->
def key = documentIssue.document.fields.find { it.name() == "key" }.stringValue()
def issue = issueManager.getIssueObject(key)
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder())
}
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.