You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

  1. The function getBillsByPlainReleaseDate expects an object with a bills property:

    function getBillsByPlainReleaseDate({ bills, plainReleaseDate }) {
      // ... uses bills.filter()
    }
    
  2. But in getNotificationFromBills, you're passing userBills instead of bills when 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 in getBillsByPlainReleaseDate would have logged undefined before the fix, which could have helped identify the issue earlier.
  • You could also refactor the function to accept userBills directly instead of destructuring, but the above fix aligns with your existing code structure.

内容的提问来源于stack exchange,提问作者Matias Aguilar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 17:15:53