Hola Comunidad, estoy empezando con Scriptrunner y he tratado de actualizar un campo de la incidencia cuando otros campos se actualizan, necesito que cuando el campo "Cantidad Disponible" ó "Costo Unitario" se actualicen entonces el valor "Costo total de inventario" también se actualice de esta forma
Cantidad Disponible*Costo Unitario
FYI =
Cantidad Disponible = Custom Field 10048
Costo Unitario = Custom Field 10033
Costo total de inventario = Custom Field 10050
Pero estoy obteniendo este error:
Calculation using null and null was not possible
Este es mi código:
// 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 == '10048' }?.id
def input2CfId = customFields.find { it.name == '10033' }?.id
def outputCfId = customFields.find { it.name == '10050' }?.id
def projectKey = "BP"
if (issue == null || ((Map)issue.fields.project).key != projectKey) {
logger.info("Wrong Project ${issue.fields.project.key}")
return
}
def input1 = issue.fields[input1CfId] as Double
def input2 = issue.fields[input2CfId] as Double
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()
He solucionado el problema de esta forma:
// these 4 values will be installation dependent
def input1CfId = 'customfield_10048' // Cantidad disponible
def input2CfId = 'customfield_10034' // Costo Unitario
def outputCfId = 'customfield_10050' // Valor Total de inventario
def projectKey = "BP"
if (issue == null || issue.fields.project.key != projectKey) {
logger.info("Wrong Project ${issue.fields.project.key}")
return
}
def input1 = issue.fields[input1CfId] as Double
def input2 = issue.fields[input2CfId] as Double
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 Double)) {
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.