I want to Bulk Edit a custom field in my project Jira Instance which I can't handle via normal Bulk Edit, so I created a Groovy script that does the update for me.
My 'searchResults.results' look like this
[com.atlassian.jira.issue.search.DocumentWithId@d9949a3e, com.atlassian.jira.issue.search.DocumentWithId@c97e3fd5, ... ]
And for each result I try to
def issueObj = issueManager.getIssueObject(it.docId)
However, 'issueObj' is always null. It would also be of use to get the issuekey as string from the search results as :
def issueObj = issueManager.getIssueObject('JIRA-123') seem to work.
Here my complete script:
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 = JIRA'
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)
log.warn("Total issues: ${searchResults.total}") // log.debug() does not work
// the name of the custom field to alter
final String customFieldName = "Impact on Architecture" // confirmed and valid field name that we want to alter
// the new value to set
final String newValue = "No"
def customField = ComponentAccessor.customFieldManager.customFieldObjects.findByName(customFieldName)
assert customField : "Could not find custom field with name $customFieldName"
searchResults.results.each {
def issueObj = issueManager.getIssueObject(it.docId) // here we try to create the object which is empty
log.warn( 'Debug:' + issueObj ) // issueobject is null
// def key = issueObj.getKey() // something like that could help
def issue = issueManager.getIssueObject('JIRA-123') // this works
log.warn( issue )
customField.updateValue(null, issue, new modifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder())
}