Hi,
I am doing sum of 2 number fields and then adding to original estimate.
Here is steps
1. Created 2 number fields ( numField1 and numField2 )
2. writing below code in behavior on numField1. When ever it get change then take the value and add with numField2 and then set to original estimate
def numField1 = getFieldById(getFieldChanged())
def numField1_Val = numField1.getValue()
def numField2 = getFieldById("customfield_17xxx") // numField2
def numField2_Val = numField2.getValue()
long totalnumFields = numField1 + numField2
def orgEstimate = getFieldById("timetracking_originalestimate")
orgEstimate.setFormValue(totalnumFields)
but this does not work. Through error
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '66' with class 'java.lang.String' to class 'long'
Look like there is some conversion required to Int but not finding it. Can anyone has any idea.
Hello @Omprakash Thamsetty
Yes, getValue returns String object, you need to convert it to long, like this
def numField1 = getFieldById(getFieldChanged())
def numField1_Val = numField1.getValue()
def numField2 = getFieldById("customfield_17xxx") // numField2
def numField2_Val = numField2.getValue()
long totalnumFields = Long.parseLong(numField1) + Long.parseLong(numField2)
def orgEstimate = getFieldById("timetracking_originalestimate")
orgEstimate.setFormValue(totalnumFields)
@Mark Markov look like I needs to import some method it seems. Getting error for long.parseLong . can you suggest me which one will be import
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You dont need to import basic java things.
There is an error, you try to convert form fields instead of values,
try to replace
long totalnumFields = Long.parseLong(numField1_Val) + Long.parseLong(numField2_Val)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mark Markov How to check for null value in behavior. Actually I am trying issue.timespent so its giving null when I create issue. Obviously it is null but how to check that and set zero in my code ? look like some below
TTSpentVal = issue.timespent
def TTSpentVal = 0
if(TTSpentVal){
TTSpentVal1=issue.timespent as Long
}else{
TTSpentVal1=0
}
but it is not checking value and setting zero. how to check value as null and set zero
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Like this
def TTSpentVal = issue.timespent
if(!TTSpentVal){
TTSpentVal=0L
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It still not checking null. Getting below error
java.lang.NullPointerException: Cannot get property 'timeSpent' on null object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Behaviour doesn's have issue variable, try to use underlyingIssue instead
def TTSpentVal = underlyingIssue?.timespent
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.