Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner and Custom Field - EVENT LISTENER

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()

 

Screen Shot 2023-10-30 at 08.06.44.png

1 answer

1 accepted

1 vote
Answer accepted

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()

Suggest an answer

Log in or Sign up to answer