Javascript Google脚本:TypeError:无法调用方法;createEvent";空的
这是我的第一个谷歌脚本,它不工作。当我启动这个脚本在脚本编辑器中测试它时,我得到了标题“…在第51行”中的错误,该标题位于“var event=cal.createEvent(title,start,end,{…”上。你能给我一个提示吗 下面的代码可以吗Javascript Google脚本:TypeError:无法调用方法;createEvent";空的,javascript,google-api,google-calendar-api,Javascript,Google Api,Google Calendar Api,这是我的第一个谷歌脚本,它不工作。当我启动这个脚本在脚本编辑器中测试它时,我得到了标题“…在第51行”中的错误,该标题位于“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
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绝对正确。因此我在这个新帖子中问你。
这意味着您的cal对象为空,因此您的
CalendarApp中有问题。getCalendarByID(calendarID)
行您可以识别代码吗?此代码很难读取是的,但是为什么?我在那里有正确的id…我找不到问题:/add console.log(calendarID)就在那一排之前,检查它是否仍然正确。我不知道是否正确