我编写了以下函数来尝试获取创建 gCal 事件的用户。
为了测试这一点,我在日历上创建了一个事件并尝试运行该脚本。当脚本执行时,会出现错误:“TypeError:无法在对象 CalendarEvent 中找到函数 getCreators。(第 68 行,文件“Code”)”。
有什么想法为什么会发生这种情况吗?我相当确定 getCreators() 是对象 CalendarEvent 中的一个函数(引用: https://developers.google.com/apps-script/reference/calendar/calendar-event#getCreators() )
function getuser(instr) {
var today = new Date();
var scriptProperties=PropertiesService.getScriptProperties();
var instrcal= scriptProperties.getProperty(instr);
var event=CalendarApp.getCalendarById(instrcal).getEventsForDay(today);
if (event<1) {
var user= 'None'
}
else if (event>1) {
var user= 'Multiple Users'
}
else {
var user= event.getCreators()
}
return user
}
最佳答案
getEventsForDay
returns an array of CalendarEvent objects ,当天的所有事件,即使只有一个。
您需要浏览事件以找到所需的事件,然后调用 getCreators()
。
您可以使用以下方法验证这一点
var event=CalendarApp.getCalendarById(instrcal).getEventsForDay(today)[0];
这里调用将起作用。
关于javascript - getCreators() 类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39750782/