How to get timespent value in behavior and set the value zero 0 if timespent is null.
I am getting below error with my code.
Here is my error
java.lang.NullPointerException: Cannot get property 'timeSpent' on null object
import org.apache.log4j.Category
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
def issueId = formContents["id"]
def issue = ComponentAccessor.getIssueManager().getIssueObject(issueId as Long)
def TTSpent = issue.timeSpent?: "0"
def TTSpentVal = TTSpent as Long
//def TTSpent = issue.timeSpent as Long
if(TTSpentVal){ //Keep the Remaining Estimate from going into a negative number
TTSpent = 0;
}
def TimeSpent = TTSpentVal / 3600
//log.debug "time spent ${TimeSpent}"
def REst = totalEstimateDEVBA - TimeSpent;
//log.debug "Remaining est ${REst}"
def remainingEstimate = getFieldById("timetracking_remainingestimate")
def remainingEstimatestr = REst.toString() + "h"
remainingEstimate.setFormValue(remainingEstimatestr)
Does anyone has any idea to convert null to zero in code.
Your problem is with the issue object itself , it return null.
@Mohamed Adel yeah. its return null but how to set zero if it is null in my code ? This is in behavior
look like some thing 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.
Try to update this line :
def TTSpent = issue.timeSpent?: "0"
with:
def TTSpent = issue?.timeSpent?: "0"
Note : Your return null object, in this case you are not checking the timeSpent value as the object itself is not exist therefore, it has no property.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.