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.