I created 5 numeric custom fields for the HELPDESK project. These fields are not used for every ticket in the project, but when they are used all 5 are mandatory.
I have a 6th numeric custom field and using script runner I am trying to fill this field based on an equation from the 5 fields.
I am using jira cloud so finding a solution on REST API.
(I am not a developer)
Getting the below Error:
The scripted field ran successfully, but returned an invalid type. Please return a number null
Code:
def input1CfId = 'customfield_10046'
def input2CfId = 'customfield_10047'
def input3CfId = 'customfield_10048'
def input4CfId = 'customfield_10049'
def input5CfId = 'customfield_10050'
def outputCfId = 'customfield_10060'
def projectKey = "HELPDESK"
def input1 = issue.fields[input1CfId] as Integer
def input2 = issue.fields[input2CfId] as Integer
def input3 = issue.fields[input3CfId] as Integer
def input4 = issue.fields[input4CfId] as Integer
def input5 = issue.fields[input5CfId] as Integer
if (input1 == null || input2 == null || input3 == null || input4 == null || input5 == null) {
logger.info("Calculation using ${input1}, ${input2}, ${input3}, ${input4}, and ${input5} was not possible")
return 0
}
def output = input1 * input2 * input3 * input4 * input5
if (output == (issue.fields[outputCfId] as Integer)) {
logger.info("already been updated")
return
}
put("/rest/api/2/issue/${issue.key}")
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output as Integer
]
])
.asString()
Can someone help me please?
The error message and the last line of your script combine to explain it. The last line says "asString()", which converts the output to a string. But you've set the field to be a number.
You just need to line up the types of output.
Sorry Nic, could you please help further? I am not familiar with coding.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You either need to target a text field for the output, or have your script return a number. To do the second, remove the .asString as a start
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.