When I define which custom fields to look at, I have a rule for:
if (input1 == null || input2 == null) {
logger.info("Calculation using \${input1} and \${input2} was not possible")
return
That is showing up as the result of my script, regardless of the fact that neither field is null. Both are number fields, with numbers and only numbers populated.
Try replacing (outputCfld) with 'Base Requested Amount:' in the put statement. I know that you are using the example that Adaptavist has in their documentation, but I suspect that the problem is that the REST call is failing silently
You might also log what the output value is to make sure that it is being calculated as expected.
What is the rest of the script that does the calculation? What you show here is missing a '}'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
// 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 == 'Development Initiative 1 Est. Cost:' }?.id
def input2CfId = customFields.find { it.name == 'Development Initiative 2 Est. Cost:' }?.id
def outputCfId = customFields.find { it.name == 'Base Requested Amount:' }?.id
def projectKey = "AFI"
if (issue == null || ((Map)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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.