Skip to content

Instantly share code, notes, and snippets.

@jechlin-adaptavist
Created May 22, 2020 20:23
Show Gist options
  • Save jechlin-adaptavist/47833f512c4e51505f53cf91ecb90586 to your computer and use it in GitHub Desktop.
Save jechlin-adaptavist/47833f512c4e51505f53cf91ecb90586 to your computer and use it in GitHub Desktop.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.onresolve.jira.groovy.jql.JqlPagedResultsUtil
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
def jqlPagedResultsUtil = ScriptRunnerImpl.scriptRunner.getBean(JqlPagedResultsUtil)
def authenticationContext = ComponentAccessor.jiraAuthenticationContext
def customFieldManager = ComponentAccessor.customFieldManager
def query = "project = TCS and updated > -14d" // add other clauses if necessary
def originalId = 13206
def newId = 14646
def preview = true
def originalCf = customFieldManager.getCustomFieldObject(originalId)
def newCf = customFieldManager.getCustomFieldObject(newId)
jqlPagedResultsUtil.query(query).setUser(authenticationContext.loggedInUser).forEachIssue { issue ->
def originalValue = issue.getCustomFieldValue(originalCf)
def newValue = issue.getCustomFieldValue(newCf)
if (newValue && !originalValue) {
def changeHolder = new DefaultIssueChangeHolder()
log.warn("Will modify issue ${issue.key}, last updated ${issue.updated}")
if (!preview) {
originalCf.updateValue(null, issue, new ModifiedValue(null, newValue), changeHolder)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment