这是我的第一个谷歌脚本,它不工作。当我开始这个脚本在脚本编辑器中测试它时,我得到的错误是站在标题"…var event = cal.createEvent(title, start, end,{…). 你能给我点小费吗?
下面的代码可以吗?
var calendarId = "xyz@group.calendar.google.com";
//Column containg the Start Date/Time for the event
var startDtId = 4;
//Column containg the End Date/Time for the event
var endDtId = 5;
//Column containg the First Part of the Title for the event (In this case, Name)
var titleId = 2;
//Column containg the Comments for the event
var descId = 3;
//Column containg the Time Stamp for the event (This will always be 1)
var formTimeStampId = 1;
//Column containg the Location
var locId = 6;
//Column containg more Informations
var infosId = 7;
function getLatestAndSubmitToCalendar() {
//Allow access to the Spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var lr = rows.getLastRow();
//Removed setting of Hour and Minute for the Start and End times as these are set in our form
var startDt = sheet.getRange(lr, startDtId, 1, 1).getValue();
var endDt = sheet.getRange(lr, endDtId, 1, 1).getValue();
//Setting the Comments as the description, and addining in the Time stamp and Submision info
var desc = "" + sheet.getRange(lr, descId, 1, 1).getValue() + "n" + subOn;
//Create the Title using the Name and tType of Absence
var title = sheet.getRange(lr, titleId, 1, 1).getValue() + " – " + sheet.getRange(lr, titleId2, 1, 1).getValue();
//Setting the Location
var loca = sheet.getRange(lr, locId, 1, 1).getValue();
//Setting more Information
var infos = sheet.getRange(lr, infosId, 1, 1).getValue();
//Run the Crete event Function
createEvent(calendarId, title, startDt, endDt, desc, loca, infos);
};
function createEvent(calendarId, title, startDt, endDt, desc, loca, infos) {
var cal = CalendarApp.getCalendarById(calendarId);
var start = new Date(startDt);
var end = new Date(endDt);
var loc = loca;
var event = cal.createEvent(title, start, end, {
description: desc,
location: loc
});
};
我在下面的线程中阅读了答案,但我的日历id绝对是正确的。因此,我在这个新帖子里问你。谷歌脚本谷歌日历类型错误:无法调用createevent方法空
这意味着你的cal对象是空的,所以你的CalendarApp.getCalendarByID(calendarID)
行有问题