Here is what I got to work in case this is helpful:
LFForm.onFieldChange(function(event) {
console.log("Field change event triggered");
// Get the date value from field 2
var dateValues = LFForm.getFieldValues({fieldId: 2});
// Check if dateValues is not empty
if (dateValues.length === 0) {
console.log("No date value found in field 2");
return;
}
var dateValue = dateValues.dateStr; // Use the dateStr property
// Log the date value to the console
console.log("Date value from field 2:", dateValue);
// Define the pay periods
var payPeriods = [
{ period: "P1", begins: "12/22/2024", ends: "1/4/2025" },
{ period: "P2", begins: "1/5/2025", ends: "1/18/2025" },
{ period: "P3", begins: "1/19/2025", ends: "2/1/2025" },
{ period: "P4", begins: "2/2/2025", ends: "2/15/2025" },
{ period: "P5", begins: "2/16/2025", ends: "3/1/2025" },
{ period: "P6", begins: "3/2/2025", ends: "3/15/2025" },
{ period: "P7", begins: "3/16/2025", ends: "3/29/2025" },
{ period: "P8", begins: "3/30/2025", ends: "4/12/2025" },
{ period: "P9", begins: "4/13/2025", ends: "4/26/2025" },
{ period: "P10", begins: "4/27/2025", ends: "5/10/2025" },
{ period: "P11", begins: "5/11/2025", ends: "5/24/2025" },
{ period: "P12", begins: "5/25/2025", ends: "6/7/2025" },
{ period: "P13", begins: "6/8/2025", ends: "6/21/2025" },
{ period: "P14", begins: "6/22/2025", ends: "7/5/2025" },
{ period: "P15", begins: "7/6/2025", ends: "7/19/2025" },
{ period: "P16", begins: "7/20/2025", ends: "8/2/2025" },
{ period: "P17", begins: "8/3/2025", ends: "8/16/2025" },
{ period: "P18", begins: "8/17/2025", ends: "8/30/2025" },
{ period: "P19", begins: "8/31/2025", ends: "9/13/2025" },
{ period: "P20", begins: "9/14/2025", ends: "9/27/2025" },
{ period: "P21", begins: "9/28/2025", ends: "10/11/2025" },
{ period: "P22", begins: "10/12/2025", ends: "10/25/2025" },
{ period: "P23", begins: "10/26/2025", ends: "11/8/2025" },
{ period: "P24", begins: "11/9/2025", ends: "11/22/2025" },
{ period: "P25", begins: "11/23/2025", ends: "12/6/2025" },
{ period: "P26", begins: "12/7/2025", ends: "12/20/2025" }
];
// Find the matching pay period
var matchingPeriod = payPeriods.find(function(period) {
var begins = new Date(period.begins);
var ends = new Date(period.ends);
var date = new Date(dateValue);
return date >= begins && date <= ends;
});
// Set the value of field 1 based on the matching pay period
if (matchingPeriod) {
LFForm.setFieldValues({fieldId: 1}, [matchingPeriod.period]);
console.log("Field 1 set to " + matchingPeriod.period);
} else {
console.log("No matching pay period found");
}
}, {fieldId: 2});