Я написал скрипт, который получает данные с одного листа и компилирует их в лист основных данных. Скрипт работает, когда я запускаю его вручную, но он не работает с установленным мной триггером времени. Я получаю сообщение об ошибке «Ошибка исключения: начальный ряд диапазона слишком мал. на MasterDataCompiling (код: 63: 42)
Это код:
function MasterDataCompiling(){
var reporting_spreadsheet = SpreadsheetApp.openById("10WGs5y3MERYezxdaN3ERKz37LiuQ6uDU6LCjo05IKvo");
var sheet = reporting_spreadsheet.getSheetByName("Google Analytics Data");
// set and store a date object for today
var date = new Date();
var one_day = 1000 * 60 * 60 * 24 * 3;
var two_days_ago = new Date(date - one_day);
Logger.log(two_days_ago);
// Get the range of dates to test
var daterange = sheet.getRange("A16:A1000").getValues();
//Logger.log(daterange);
// iterate the values in the range object
for(var i=0; i<daterange.length; i++) {
// Compare only month/day/year in the date objects
if(new Date(daterange[i]).setHours(0,0,0,0) == two_days_ago.setHours(0,0,0,0)) {
// if there's a match, set the row
// i is 0 indexed, so add 3 to get the correct row
var today_row = (i);
// rest of your code
}
}
var row_values = sheet.getRange(16+today_row,1,1,7).getValues();
var one_day_active_users = row_values[0][1];
var pageviews = row_values[0][2];
var total_events = row_values[0][3];
var adsense_rev = row_values[0][4];
var adsense_units_viewed = row_values[0][5];
var org_searches = row_values[0][6];
Logger.log(one_day_active_users, pageviews, total_events, adsense_rev,adsense_units_viewed, org_searches);
//youtube metrics
var youtube_sheet = reporting_spreadsheet.getSheetByName("Youtube");
var youtube_daterange = youtube_sheet.getRange("A2:A1000").getValues();
// Logger.log(youtube_daterange);
// iterate the values in the range object
for(var i=0; i<youtube_daterange.length; i++) {
// Compare only month/day/year in the date objects
if(new Date(youtube_daterange[i]).setHours(0,0,0,0) == two_days_ago.setHours(0,0,0,0)) {
// if there's a match, set the row
// i is 0 indexed, so add 3 to get the correct row
var youtube_today_row = (i);
Logger.log(youtube_today_row);
// rest of your code
}
}
var youtube_row_values = youtube_sheet.getRange(2+youtube_today_row,1,1,8).getValues();
var est_views = youtube_row_values[0][1];
var est_min_watched = youtube_row_values[0][2];
var yt_likes = youtube_row_values[0][3];
var yt_dislikes = youtube_row_values[0][4];
var yt_comm = youtube_row_values[0][5];
var yt_subs_gain = youtube_row_values[0][6];
var yt_subs_lost = youtube_row_values[0][7];
Logger.log(est_views, est_min_watched, yt_likes, yt_dislikes, yt_comm, yt_subs_gain, yt_subs_lost);
//insta metrics
var insta_sheet = reporting_spreadsheet.getSheetByName("Instagram");
var insta_daterange = insta_sheet.getRange("A2:A1000").getValues();
// iterate the values in the range object
for(var i=0; i<insta_daterange.length; i++) {
// Logger.log(insta_daterange[i], two_days_ago);
// Compare only month/day/year in the date objects
if(new Date(insta_daterange[i]).setHours(0,0,0,0) == two_days_ago.setHours(0,0,0,0)) {
// if there's a match, set the row
// i is 0 indexed, so add 3 to get the correct row
var insta_today_row = (i);
Logger.log(insta_today_row);
// rest of your code
}
}
var insta_row_values = insta_sheet.getRange(2+insta_today_row,1,2,10).getValues();
var followers = insta_row_values[1][1];
var following = insta_row_values[1][2];
var posts = insta_row_values[1][3];
var daily_views = insta_row_values[0][4];
var engagements = insta_row_values[0][5];
var ig_video_views = insta_row_values[0][6];
var ig_comments = insta_row_values[0][7];
var ig_website_clicks = insta_row_values[0][8];
Logger.log(followers, following, posts, daily_views, engagements, ig_video_views, ig_comments, ig_website_clicks);
SpreadsheetApp.flush();
var blog_sheet = reporting_spreadsheet.getSheetByName("Website");
var blog_cat_count = blog_sheet.getRange("I4:I15").getValues();
var fitness = blog_cat_count[0][0];
var gen_info = blog_cat_count[1][0];
var mental = blog_cat_count[2][0];
var news = blog_cat_count[3][0];
var nutrition = blog_cat_count[4][0];
var physio = blog_cat_count[5][0];
var gear = blog_cat_count[6][0];
var rules = blog_cat_count[7][0];
var tactics = blog_cat_count[8][0];
var techniq = blog_cat_count[9][0];
var uncat = blog_cat_count[10][0];
var workout = blog_cat_count[11][0];
var total_posts_blog = blog_sheet.getRange("J4").getValue();
var pasting_array = [[two_days_ago,
one_day_active_users,
pageviews,
total_events,
adsense_rev,
adsense_units_viewed,
org_searches,
total_posts_blog,
fitness,
gen_info,
mental,
news,
nutrition,
physio,
gear,
rules,
tactics,
techniq,
uncat,
workout,
est_views,
est_min_watched,
yt_likes,
yt_dislikes,
yt_comm,
yt_subs_gain,
yt_subs_lost,
followers,
following,
posts,
daily_views,
engagements,
ig_video_views,
ig_comments,
ig_website_clicks]]
Logger.log(pasting_array);
var copyToSheet = reporting_spreadsheet.getSheetByName("Master Data");
copyToSheet.getRange(copyToSheet.getLastRow()+1, 1,1,35).setValues(pasting_array);
}
```
Any idea why this would be happening?