import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.query.Query
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.bc.issue.search.searchservice
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
I ID for the old "Work Type" custom field that was a multi-select field
Long workTypeFieldId = 13856L
// ID for the new "Work Type custom field" that is a single-select field
Long newhorkTypeFieldId = 30439L
CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
I/ getting the "work Type" custom field
//ustomField workTypeField = customFieldManager.getCustomFieldobject(workTypeFieldId)
CustomField newworkTypeField = customFieldManager.getcustomFieldobject (newworkTypeFieldrd)
IssueManager issueManager = ComponentAccessor.issueManager
// Username for the user that we will run the script as
String svcAccountUsername = 'beacon'
// Getting the user from Dira based off of the username
ApplicationUser user = ComponentAccessor.userManager.getuserByName(svcAccountUsername)
I/ Building and executing the query to find all issues with the old work type field that do not have an empty value
String jqlstr = 'cf[13848] is NOT EMPTY'
Searchservice searchservice = ComponentAccessor.getcomponent(Searchservice.class)
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlstr)
// Getting results for 10 issues (script will need to update every issue, but doing all at once could put Jira into a bad state)
SearchResults searchResults = searchService. search(user, parseResult.query, PagerFilter.newpageAlignedFilter(@, 10))
// Iterating over all issues that were found
for (Issue issue : searchResults.results) {
// Get the Work Type custom field value from each issue
def val = issue.getcustomFieldvalue (workTypeField)
// Get first item from array
// TODO: put the first result from the array into the new custom field on the issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.