Google Apps Script出现TypeError: Cannot read property 'filter' of undefined报错排查
Fix for TypeError: Cannot read property 'filter' of undefined
The error occurs because of a variable naming mismatch when calling the getBillsByPlainReleaseDate function. Here's the breakdown:
The function
getBillsByPlainReleaseDateexpects an object with abillsproperty:function getBillsByPlainReleaseDate({ bills, plainReleaseDate }) { // ... uses bills.filter() }But in
getNotificationFromBills, you're passinguserBillsinstead ofbillswhen invoking the function:const billsReleasedToday = getBillsByPlainReleaseDate({userBills, plainReleaseDate: releasedToday});
Solution
Update all calls to getBillsByPlainReleaseDate to use the correct key name bills instead of userBills:
// Replace these lines: const billsReleasedToday = getBillsByPlainReleaseDate({userBills, plainReleaseDate: releasedToday}); const billsReleased30DaysAgo = getBillsByPlainReleaseDate({ userBills, plainReleaseDate: due30Days }); const billsReleased45DaysAgo = getBillsByPlainReleaseDate({ userBills, plainReleaseDate: overDue45Days }); const billsReleased60DaysAgo = getBillsByPlainReleaseDate({ userBills, plainReleaseDate: overDue60Days }); // With these: const billsReleasedToday = getBillsByPlainReleaseDate({bills: userBills, plainReleaseDate: releasedToday}); const billsReleased30DaysAgo = getBillsByPlainReleaseDate({ bills: userBills, plainReleaseDate: due30Days }); const billsReleased45DaysAgo = getBillsByPlainReleaseDate({ bills: userBills, plainReleaseDate: overDue45Days }); const billsReleased60DaysAgo = getBillsByPlainReleaseDate({ bills: userBills, plainReleaseDate: overDue60Days });
Additional Notes
- The
console.log("Running getBills: " + bills)line ingetBillsByPlainReleaseDatewould have loggedundefinedbefore the fix, which could have helped identify the issue earlier. - You could also refactor the function to accept
userBillsdirectly instead of destructuring, but the above fix aligns with your existing code structure.
内容的提问来源于stack exchange,提问作者Matias Aguilar
相关产品推荐
相关产品推荐

