I have a requirement to automatically calculate a person's age based on the value of entered in the DOB field. Am very new to scripting but have tried the below script to no success, It is not returning the person's age. I used the ScriptRunner scripted field and my selected template is "Date Time" and my searcher is "Date Time Picker Range" Please, I need some help
import com.atlassian.jira.component.ComponentAccessor
import java.time.Period
import java.time.LocalDate
import java.time.ZoneId
def customFieldManager = ComponentAccessor.customFieldManager
def dob = customFieldManager.getCustomFieldObjectsByName("DOB")[0]
def dobValue = dob.getValue(issue) as Date
static def convertToLocalDateViaInstant(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate()
}
def today = LocalDate.now()
def birthday = convertToLocalDateViaInstant(dobValue) as LocalDate
def age = Period.between(birthday, today)
return String.format("%d years, %d months, %d days", age.getYears(), age.getMonths(), age.getDays())