我有一个已经运行了近2年的脚本。我使用日期更新工作表,并删除/创建事件或创建新事件。
这是我最后一次通过并添加我的日期正常情况下,它使用事件ID填充表格单元格,并且我正在以愉快的方式 - 但是当我去日历时,没有显示该日期/时间。< / p>
我是否缺少新的权限 - 没有抛出任何错误 - 日志中没有任何内容。我有一个事件ID,但我不知道如何查看显示的内容,因为我在日历上看不到它 - 有没有办法检查事件ID并查看它包含的内容。
表格(我用管道分开)
主题|开始日期|开始时间|结束日期|结束时间|全天活动|会议组织者|描述|位置|提醒日期|提醒时间|显示时间为|活动ID |状态 调查编辑:HC交付科学| 08/07/2017 | 12:00:00 AM | 8/7/2017 | 12:00:00 PM | TRUE | Seamore Butz ||| 8/7/2017 | 9:00 :00 AM | 3 sg5a7jsakgbj8g5rejeos15lhc@google.com|y
function pushToCalendar()
{
//spreadsheet variables
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
/*
getRange (row,column,optNumRows,optNumColumns)
row --- int --- top row of the range
column --- int--- leftmost column of the range
optNumRows --- int --- number of rows in the range.
optNumColumns --- int --- number of columns in the range
*/
var range = sheet.getRange(2,1,lastRow,13);
var values = range.getValues();
//calendar variables
// xxxxxxxxxxxxxxxxxxxxxxxxxx@group.calendar.google.com
var calendar = CalendarApp.getCalendarById('xxxxxxxxxxxxxxxxxxxxx@group.calendar.google.com')
var numValues = 0;
for (var i = 0; i < values.length; i++)
{
//check to see if name and type are filled out - date is left off because length is "undefined"
if (values[i][0].length > 0)
{
//check if it's been entered before
if (values[i][13] == undefined)
{
//create event https://developers.google.com/apps-script/class_calendarapp#createEvent
var newEventTitle = values[i][0];
Logger.log(newEventTitle);
var dateStart = values[i][1];
var timeStart = values[i][2];
var dateFinish = values[i][3];
var timeFinish = values[i][4];
var startDateTime = new Date(dateStart+" "+timeStart);
startDateTime.setDate(startDateTime.getDate());
startDateTime.setMonth(startDateTime.getMonth());
startDateTime.setYear(startDateTime.getYear());
startDateTime.setTime(startDateTime.getTime());
var stopDateTime = new Date(dateFinish+" "+timeFinish);
stopDateTime.setDate(stopDateTime.getDate());
stopDateTime.setMonth(stopDateTime.getMonth());
stopDateTime.setYear(stopDateTime.getYear());
stopDateTime.setTime(stopDateTime.getTime());
var description = (values[i][7] == '' ? 'Test Description '+i : values[i][7]);
var location = (values[i][8] == '' ? 'Test Location '+i : values[i][8]);
Logger.log(description);
Logger.log(location);
//var newEvent = calendar.createAllDayEvent(newEventTitle, values[i][1]);
var newEvent = calendar.createEvent(newEventTitle, startDateTime, stopDateTime, {description:description,location:location});
//get ID
var newEventId = newEvent.getId();
//mark as entered, enter ID
sheet.getRange(i+2,14).setValue('y');
sheet.getRange(i+2,13).setValue(newEventId);
// in case of larger sheets we need to sleep the process
Utilities.sleep(1000);
}
else if (values[i][14] == 'u')
{
// can update event so need to delete and create again
// delete event
var event = calendar.getEventSeriesById(values[i][9]);
event.deleteEventSeries();
//create event
var newEventTitle = values[i][0];
//create event https://developers.google.com/apps-script/class_calendarapp#createEvent
var newEventTitle = values[i][0];
var dateStart = values[i][1];
var timeStart = values[i][2];
var dateFinish = values[i][3];
var timeFinish = values[i][4];
var startDateTime = new Date(dateStart+" "+timeStart);
startDateTime.setDate(startDateTime.getDate());
startDateTime.setMonth(startDateTime.getMonth());
startDateTime.setYear(startDateTime.getYear());
startDateTime.setTime(startDateTime.getTime());
var stopDateTime = new Date(dateFinish+" "+timeFinish);
stopDateTime.setDate(stopDateTime.getDate());
stopDateTime.setMonth(stopDateTime.getMonth());
stopDateTime.setYear(stopDateTime.getYear());
stopDateTime.setTime(stopDateTime.getTime());
var description = (values[i][7] == undefined ? 'Test Description '+i : values[i][7]);
var location = (values[i][8] == undefined ? 'Test Location '+i : values[i][8]);
//var newEvent = calendar.createAllDayEvent(newEventTitle, values[i][1]);
var newEvent = calendar.createEvent(newEventTitle, startDateTime, stopDateTime, {description:description,location:location});
//get ID
var newEventId = newEvent.getId();
//mark as entered, enter ID
sheet.getRange(i+2,14).setValue('y');
sheet.getRange(i+2,13).setValue(newEventId);
// in case of larger sheets we need to sleep the process
Utilities.sleep(1000);
}
else
{
Logger.log('I am groot');
sheet.getRange(i+2,14).setValue('y');
}
}
numValues++;
}
}
function onOpen()
{
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Grades & Evals", functionName: "pushToCalendar"});
sheet.addMenu("Sync to Academic Master", menuEntries);
}
答案 0 :(得分:0)
我最终发现了这个问题..在记录更多并搜索无效日期响应后发现了一个小问题。
第16行
var values = range.getValues();
需要更改为
var values = range.getDisplayValues();
非常感谢:)。