In a google sheet I have a self populating list of twitter tweets and I'm trying to filter out all tweets from the previous day.
I keep getting an error:
"Cannot read property 'length' of undefined"
Error is on the last line of the code
targetSheet.getRange(1,1, filteredData.length, filteredData[0].length).setValues(filteredData);
function FilterByDate() { var sSheet = SpreadsheetApp.getActiveSpreadsheet(); var sourceSheet = sSheet.getSheetByName("Tweets"); var targetSheet = sSheet.getSheetByName("FilteredTweets"); var TodaysDate = new Date(); TodaysDate.setHours(00, 00, 00, 001) var TargetDate = new Date(TodaysDate.getTime() - (24 * 60 * 60 * 1000); //Hours, Mins, Secs, Milisecs var data = sourceSheet.getDataRange().getValues(); var filteredData = data.filter(dataRow => (dataRow[1] == TargetDate)); targetSheet.getRange(1,1, filteredData.length, filteredData[0].length).setValues(filteredData); }
I use this same code to filter different data on another sheet and it works fine.
This is the first time I've tried to use it to filter by date.
Date Time is column A on the sourceSheet.
I don't understand why it dosent work here. Please help!
https://stackoverflow.com/questions/67013745/google-app-script-typeerror-cannot-read-property-length-of-undefined April 09, 2021 at 09:05AM
没有评论:
发表评论