Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Null to Zero in Script Listner

Rao Tripuraneni August 21, 2023

Hello- I hope some one can help me fix the problem am facing with a piece of code i have written(i am very new to the coding)

i have 3 Number fields and want to sum 2 fields into the 3rd one.This work fine as long as the user doesnt NULL out one of the fields and SUM is failing to handle NULL.

 

Please advise.

 

// 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 == 'Dev Story Points' }?.id
def input2CfId = customFields.find { it.name == 'QA Story Points' }?.id
def outputCfId = customFields.find { it.name == 'Story Points' }?.id
def projectKey = "CIW"

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}")
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events