// Specify the issue key to update
def issueKey = '<IssueKeyHere>'
// Specify the name of the select list field to set
def selectListFieldName = '<SelectListFieldNameHere>'
// Get the Custom field to get the option value from
def customField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == selectListFieldName
} as Map
// Check if the custom field returns a valid field and is not null
assert customField != null : "Cannot find custom field with name of: ${selectListFieldName}"
def result = put("/rest/api/2/issue/${issueKey}")
// Uncomment the line below if you want to set a field which is not pressent on the screen. Note - If using this you must run the script as the ScriptRunner Add-On User.
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
(
customField.id):[value: "<OptionValueHere>"] as Map
]
])
.asString()
if (result.status == 204) {
return "The ${
customField.name} select list field was successfully updated on the ${issueKey} issue"
} else {
return "${result.status}: ${result.body}"
}