Forums

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

JIRA Script Behavior to update custom field with caluculated value

Timothy Kidd August 24, 2018

I am trying to add a behavior on a custom field that sums up values from several custom field and save that value to another custom field.  Everything works except the addition (bolded line).  It is a simple addition and I don't understand why simple addition is giving an error.  I tried to force conversion to .toInteger() and it still don't work.

 

def cfTimeCriticality = getFieldByName("Time Criticality")?:0
def cfUserBizValue = getFieldByName("User/Biz")
def cfRROE = getFieldByName("RR/OE")
def cfCostOfDelay = getFieldByName("Cost of Delay")

def RROE = cfRROE.getValue()?:0
def UserBizValue = cfUserBizValue.getValue()?:0
def CostOfDelay = RROE + UserBizValue

cfCostOfDelay.setFormValue(CostOfDelay)

2 answers

1 accepted

0 votes
Answer accepted
Timothy Kidd August 24, 2018

Solved the issue with the following code for the WSJF calculation.  What is interesting is that script adds "48" to the value.  I don't understand why this is the case but so far it worked for multiple projects and issues.

 

def cfTimeCriticality = getFieldByName("Time Criticality")
def cfUserBizValue = getFieldByName("User/Biz Value")
def cfRROE = getFieldByName("RR/OE")
def cfCostOfDelay = getFieldByName("Cost of Delay")
def cfJobSize = getFieldByName("Job Size")
def cfWSJF = getFieldByName("WSJF")

def RROE = (Integer)cfRROE.getValue()?:0
def UserBizValue = (Integer)cfUserBizValue.getValue()?:0
def TimeCriticality = (Integer)cfTimeCriticality.getValue()?:0
def JobSize = cfJobSize = (Integer)cfJobSize.getValue()?:0
def CostOfDelay = (RROE - 48) + (UserBizValue - 48) + (TimeCriticality - 48)

cfCostOfDelay.setFormValue(CostOfDelay)

cfWSJF.setFormValue(CostOfDelay/(JobSize - 48))

0 votes
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2018

Hello @Timothy Kidd

All fields are numeric?

Timothy Kidd August 24, 2018

Yes

def cfTimeCriticality = getFieldByName("Time Criticality")
def cfUserBizValue = getFieldByName("User/Biz Value")
def cfRROE = getFieldByName("RR/OE")
def cfCostOfDelay = getFieldByName("Cost of Delay")
def cfWSJF = getFieldByName("WSJF")

def RROE = cfRROE.getValue()?:0
def UserBizValue = cfUserBizValue.getValue()?:0
def TimeCriticality = cfTimeCriticality.getValue()?:0

def CostOfDelay = (Integer)RROE + (Integer)UserBizValue + (Integer)TimeCriticality

cfCostOfDelay.setFormValue(CostOfDelay)
cfWSJF.setFormValue(TimeCriticality)

 

Finally addition doesn't give error but calculation is incorrect.  1+1+1 = 147

lol..  what obvious thing am i overlooking?

Suggest an answer

Log in or Sign up to answer