Hi there
I'm trying to use Adaptavist's sample code to calculate a custom field on Issue Update.
I'm using the code template as-is, only modifying the issue field names as per my issue type. but I seem to be getting a type conversion error:
2018-10-09 04:32:57.096 INFO - Serializing object into 'interface java.util.List'
2018-10-09 04:32:57.137 INFO - GET /rest/api/2/field asObject Request Duration: 875ms
2018-10-09 04:32:57.175 ERROR - Cannot coerce a map to class java.lang.Integer because it is a final class on line 17
2018-10-09 04:32:57.177 ERROR - Class: com.adaptavist.sr.cloud.events.WebhookExecution, Config: null
I used the "Calculated Custom Field" link to insert the template on the add new listener page, but it's pretty much as per the following:
https://scriptrunner-docs.connect.adaptavist.com/jiracloud/script-listeners.html#_calculate_custom_field_on_issue_update
Here is my script:
// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def input1CfId = customFields.find { it.name == 'Potential Impact' }?.id
def input2CfId = customFields.find { it.name == 'Likelihood' }?.id
def outputCfId = customFields.find { it.name == 'Severity' }?.id
def projectKey = "IMPT"
if (issue == null || (issue.fields.project).key != projectKey) {
logger.info("Wrong Project \${issue.fields.project.key}")
return
}
def input1 = issue.fields[input1CfId] as Integer
def input2 = issue.fields[input2CfId] as Integer
if (input1 == null || input2 == null) {
logger.info("Calculation using \${input1} and \${input2} was not possible")
return
}
def output = input1 * input2
if (output == (issue.fields[outputCfId] as Integer)) {
logger.info("already been updated")
return
}
put("/rest/api/2/issue/\${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()
Can anyone tell me what the issue is, please?
Cheers,
Paul