I am using the Scriptrunner listener capability of Jira cloud version to update a custom field called "Last comment" when comment is updated/created on an issue. I get the following error:
2020-01-08 21:09:54.798 INFO - Serializing object into 'interface java.util.List'
2020-01-08 21:09:54.806 INFO - GET /rest/api/2/field asObject Request Duration: 604ms
2020-01-08 21:09:55.554 INFO - Serializing object into 'interface java.util.Map'
2020-01-08 21:09:55.558 INFO - GET /rest/api/2/issue/PP-151 asObject Request Duration: 715ms
2020-01-08 21:09:55.845 WARN - PUT request to /rest/api/2/issue/PP-151 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"customfield_10943":"Field 'customfield_10943' cannot be set. It is not on the appropriate screen, or unknown."}}
2020-01-08 21:09:55.846 INFO - PUT /rest/api/2/issue/PP-151 asString Request Duration: 284msHere is my script:
// Specify the issue key to update
def issueKey = issueKey
// Specify the name of the select list field to set
def selectListFieldName = 'Last comment'
// 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
// Fetch the issue object from the key
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
// Get the comment
def commentField = (issue.fields as Map).comment as Map
def comments = commentField.get('comments') as Map
def mapSize = comments.size()
if (mapSize == 0) {
return
}
def lastComment = ((comments[mapSize-1]) as Map).body
def result = put("/rest/api/2/issue/${issueKey}")
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
"${customField.key}":[value: "${lastComment}"] as Map
]
])
.asString()
if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}