Hi Everyone,
I'm having trouble writing a formula for a calculated value field.
Here's what I'm trying to do:
-Calculate the estimated age of person/record using their medical school graduation year
-Use a field called 'medicalSchoolGraduationYear' that contains the year they graduated
-Get current year
-Assume they were 22 years old at graduation
-Calculation: Current year - graduation year +22 For example, 2023- 2000+ 22= 45 years old
-Display calculated value (estimated age) in a field called 'estimatedAge'
-This would display anytime a record is viewed by a user, not only when it is saved.
Here's what Chat GPT suggests (does not work so far):
var graduationYear = parseInt(fields['graduation_year']); // Assuming 'graduation_year' is the name of the graduation year field
var currentYear = new Date().getFullYear();
if (graduationYear && graduationYear <= currentYear) {
fields['estimatedAge'] = currentYear - graduationYear + 22;
} else {
fields['estimatedAge'] = null; // Set the field to null if graduation year is missing or in the future
}
Any suggestions? Thanks so much!
I'm having trouble writing a formula for a calculated value field.
Here's what I'm trying to do:
-Calculate the estimated age of person/record using their medical school graduation year
-Use a field called 'medicalSchoolGraduationYear' that contains the year they graduated
-Get current year
-Assume they were 22 years old at graduation
-Calculation: Current year - graduation year +22 For example, 2023- 2000+ 22= 45 years old
-Display calculated value (estimated age) in a field called 'estimatedAge'
-This would display anytime a record is viewed by a user, not only when it is saved.
Here's what Chat GPT suggests (does not work so far):
var graduationYear = parseInt(fields['graduation_year']); // Assuming 'graduation_year' is the name of the graduation year field
var currentYear = new Date().getFullYear();
if (graduationYear && graduationYear <= currentYear) {
fields['estimatedAge'] = currentYear - graduationYear + 22;
} else {
fields['estimatedAge'] = null; // Set the field to null if graduation year is missing or in the future
}
Any suggestions? Thanks so much!
Comment