将谷歌表单回复发送到谷歌日历

时间:2015-09-01 20:46:10

标签: javascript google-calendar-api

我最近开始了一个项目,允许不同人群之间的沟通,以确认会议的约会。问题是我似乎无法将表单中的响应发送到我放入函数中的Google日历ID。

有人可以解释代码出了什么问题或引导我朝正确的方向解决这个问题吗?

以下是代码:

//Function records responses and sends them to a google calendar.

function onFormSubmit(e) {

    var form = FormApp.getActiveForm(); // opens active form

    var usarResponses = form.getResponses(); // collects responses

    //Loop creates an array for responses
    for(var i = 0; i < usarResponses.length; i++){
    var usarResponse = usarResponses[i];
    }

    //responses are put into variables.

    var name = usarResponses[0];
    var appointmentName = usarResponses[1];
    var appointmentDate = usarResponses[2];
    var uDescription = usarResponses[3];


    var cal = CalendarApp.getCalendarById('kq14it8fl42i560gl6ueeo4qu8@group.calendar.google.com').createEvent(appointmentName, new Date(appointmentDate), new Date('8:00:00  UTC') , {description: uDescription});
}

1 个答案:

答案 0 :(得分:0)

这是一个棘手的问题。这是对我有用的东西:

function createEvent() {
var form = FormApp.getActiveForm();
var cal = CalendarApp.getDefaultCalendar();
var responses = form.getResponses();
var len = responses.length;
var last = len – 1;
var items = responses[last].getItemResponses();
var email = responses[last].getRespondentEmail();
var name = items[0].getResponse();
var bring = items[1].getResponse();
var date = items[2].getResponse();
Logger.log(date);
var replace = date.replace(/-/g,”/”);
Logger.log(replace);
var start = new Date(replace);
Logger.log(‘start ‘+start);

//Logger.log(newStart.getHours());
var endHours = 2+0+start.getHours();//2 hour event

//Logger.log(start.getDay());
var day = start.getDate();
var minutes = start.getMinutes();
var year = start.getFullYear();
var month = start.getMonth();
var hours = start.getHours();

var d = new Date(year, month, day, endHours, minutes);
Logger.log(d);

var event = cal.createEvent(‘Class Party ‘+name+’ brings ‘+bring, start, d)
.addGuest(email)
.setDescription(name+’ you will be bringing ‘+bring+’ to the party.’);

GmailApp.sendEmail(email, name+’ a Google Calendar invite has been created for you’, name+’ You filled out the Google Form for the date of ‘+start+’. Check your Google Calendar to confirm that you received the invite.\n’);

}