将 google sheet 表单回复组合成 google 日历事件的描述
Combining google sheet form responses into a description for google calendar event
我是脚本编写的新手,一直在尝试将它们组合在一起,而无需购买扩展程序或使用 chrome 附加组件。
我不仅希望能够获取 Goggle 脚本表单回复,还希望能够获取表单回复电子表格的额外列(我在其中处理了不同列中的一些回复)并使用它来设置日历约会,其中描述是操作数据的列(不是数据的原始响应列)。在下面的示例中,我希望日历描述是 [Combo Description] 列,它表示两个表单响应的 arrayformula 组合:[Event Description] 和 [New Description],每个表单响应都出现在定义的日历中。
这是我尝试修改的示例,它是我尝试做的更详细内容的简化版本。
我的示例表单在这里
https://docs.google.com/forms/d/1EcafKYmstMiPcIhYpEsnvmf47yyeWNiYZIyxr93QkPU/edit?usp=sharing
支持的 google 电子表格在这里:
https://docs.google.com/spreadsheets/d/1db6n-d88KrCWKXMuaFYYOU75pNOAysqwBuc7aORkmKE/edit?usp=sharing
我正在使用来自以下网站的脚本的修改版本:
http://www.jessespevack.com/blog/2016/2/9/turn-a-google-form-response-into-a-calendar-event
这是 my/his 脚本的副本:
//Load the Moment.js library once.
var moment = Moment.load();
var GLOBAL = {
//the id of the form we will use to create calendar events
formId : "1EcafKYmstMiPcIhYpEsnvmf47yyeWNiYZIyxr93QkPU",
//the id of the calendar we will create events on
calendarId : "81hoju2sgoldcjom4888opngk0@group.calendar.google.com",
//a mapping of form item titles to sections of the calendar event
formMap : {
eventTitle: "Event Title",
startTime : "Event Date and Start Time",
endTime: "Event Date and End Time",
description: "Event Description", // Tried the following: + , & concate col[6]:which didn't throw an error but didn't make an appointment either
location: "Event Location",
email: "Add Guests",
},
}
function onFormSubmit() {
var eventObject = getFormResponse();
var event = createCalendarEvent(eventObject);
}
function getFormResponse() {
// Get a form object by opening the form using the
// form id stored in the GLOBAL variable object
var form = FormApp.openById(GLOBAL.formId),
//Get all responses from the form.
//This method returns an array of form responses
responses = form.getResponses(),
//find the length of the responses array
length = responses.length,
//find the index of the most recent form response
//since arrays are zero indexed, the last response
//is the total number of responses minus one
lastResponse = responses[length-1], // The -1 goes after length
//get an array of responses to every question item
//within the form for which the respondent provided an answer
itemResponses = lastResponse.getItemResponses() // Took a comma off here
//create an empty object to store data from the last
//form response
//that will be used to create a calendar event
eventObject = {};
//Loop through each item response in the item response array
for (var i = 0, x = itemResponses.length; i<x; i++) {
//Get the title of the form item being iterated on
var thisItem = itemResponses[i].getItem().getTitle(),
//get the submitted response to the form item being
//iterated on
thisResponse = itemResponses[i].getResponse();
//based on the form question title, map the response of the
//item being iterated on into our eventObject variable
//use the GLOBAL variable formMap sub object to match
//form question titles to property keys in the event object
switch (thisItem) {
case GLOBAL.formMap.eventTitle:
eventObject.title = thisResponse;
break;
case GLOBAL.formMap.startTime:
eventObject.startTime = thisResponse;
break;
case GLOBAL.formMap.endTime:
eventObject.endTime = thisResponse;
break;
case GLOBAL.formMap.description:
eventObject.description = thisResponse;
break;
case GLOBAL.formMap.location:
eventObject.location = thisResponse;
break;
case GLOBAL.formMap.email:
eventObject.email = thisResponse;
break;
}
}
return eventObject;
}
function createCalendarEvent(eventObject) {
//Get a calendar object by opening the calendar using the
//calendar id stored in the GLOBAL variable object
var calendar = CalendarApp.getCalendarById(GLOBAL.calendarId),
//The title for the event that will be created
title = eventObject.title,
//The start time and date of the event that will be created
startTime = moment(eventObject.startTime).toDate(),
//The end time and date of the event that will be created
endTime = moment(eventObject.endTime).toDate();
//an options object containing the description and guest list
//for the event that will be created
var options = {
description : eventObject.description,
guests : eventObject.email,
location: eventObject.location,
};
try {
//create a calendar event with given title, start time,
//end time, and description and guests stored in an
//options argument
var event = calendar.createEvent(title, startTime,
endTime, options)
} catch (e) {
//delete the guest property from the options variable,
//as an invalid email address with cause this method to
//throw an error.
delete options.guests
//create the event without including the guest
var event = calendar.createEvent(title, startTime,
endTime, options)
}
return event;
Logger.log(event);
}
/***
For later to make the endDate be a fixed 2hr appointment
var submittedDate = new Date(userSubmission);
var parsedDate = Date.parse(submittedDate);
var endDate = new Date(parsedDate + 120000);
**/
请就如何将表格电子表格的额外列添加到日历建议中提出任何提示或建议,我们将不胜感激!!!
首先,因为您只是组合了 New Description
和 Event Description
项目来创建新的描述。您不需要使用数组公式和 google 工作表来组合它。您可以在应用程序脚本本身中执行此操作。
修改:
1) 您必须从表单中检索这个新项目(新描述)。您将修改您的 formmap 对象,以包含这个新项目
formMap : {
eventTitle: "Event Title",
startTime : "Event Date and Start Time",
endTime: "Event Date and End Time",
description: "Event Description", // Tried the following: + , & concate col[6]:which didn't throw an error but didn't make an appointment either
location: "Event Location",
email: "Add Guests",
newdescription : "New Description" //New entery
}
2) 您将获得用户在 switch case 语句中创建的新条目,如下所示:
switch (thisItem) {
case GLOBAL.formMap.eventTitle:
eventObject.title = thisResponse;
break;
case GLOBAL.formMap.startTime:
eventObject.startTime = thisResponse;
break;
case GLOBAL.formMap.endTime:
eventObject.endTime = thisResponse;
break;
case GLOBAL.formMap.description:
eventObject.description = thisResponse;
break;
case GLOBAL.formMap.location:
eventObject.location = thisResponse;
break;
case GLOBAL.formMap.email:
eventObject.email = thisResponse;
break;
case GLOBAL.formMap.newdescription:
eventObject.newdescription = thisResponse; //New description entry
break;
}
3) 然后要制作组合描述,您只需加入字符串描述和新描述。
var comboDescription = eventObject.description+" "+eventObject.newdescription
并使用这个新的 comboDescription 创建您的日历事件。
var comboDescription = eventObject.description+" "+eventObject.newdescription
var options = {
description : comboDescription,
guests : eventObject.email,
location: eventObject.location,
};
完成所有这些修改后,您的最终代码将是:
var GLOBAL = {
//the id of the form we will use to create calendar events
formId : "1EcafKYmstMiPcIhYpEsnvmf47yyeWNiYZIyxr93QkPU",
//the id of the calendar we will create events on
calendarId : "81hoju2sgoldcjom4888opngk0@group.calendar.google.com",
//a mapping of form item titles to sections of the calendar event
formMap : {
eventTitle: "Event Title",
startTime : "Event Date and Start Time",
endTime: "Event Date and End Time",
description: "Event Description", // Tried the following: + , & concate col[6]:which didn't throw an error but didn't make an appointment either
location: "Event Location",
email: "Add Guests",
newdescription : "New Description" //New entery
},
}
function onFormSubmit() {
var eventObject = getFormResponse();
var event = createCalendarEvent(eventObject);
}
function getFormResponse() {
// Get a form object by opening the form using the
// form id stored in the GLOBAL variable object
var form = FormApp.openById(GLOBAL.formId),
//Get all responses from the form.
//This method returns an array of form responses
responses = form.getResponses(),
//find the length of the responses array
length = responses.length,
//find the index of the most recent form response
//since arrays are zero indexed, the last response
//is the total number of responses minus one
lastResponse = responses[length-1], // The -1 goes after length
//get an array of responses to every question item
//within the form for which the respondent provided an answer
itemResponses = lastResponse.getItemResponses() // Took a comma off here
//create an empty object to store data from the last
//form response
//that will be used to create a calendar event
eventObject = {};
//Loop through each item response in the item response array
for (var i = 0, x = itemResponses.length; i<x; i++) {
//Get the title of the form item being iterated on
var thisItem = itemResponses[i].getItem().getTitle(),
//get the submitted response to the form item being
//iterated on
thisResponse = itemResponses[i].getResponse();
//based on the form question title, map the response of the
//item being iterated on into our eventObject variable
//use the GLOBAL variable formMap sub object to match
//form question titles to property keys in the event object
switch (thisItem) {
case GLOBAL.formMap.eventTitle:
eventObject.title = thisResponse;
break;
case GLOBAL.formMap.startTime:
eventObject.startTime = thisResponse;
break;
case GLOBAL.formMap.endTime:
eventObject.endTime = thisResponse;
break;
case GLOBAL.formMap.description:
eventObject.description = thisResponse;
break;
case GLOBAL.formMap.location:
eventObject.location = thisResponse;
break;
case GLOBAL.formMap.email:
eventObject.email = thisResponse;
break;
case GLOBAL.formMap.newdescription:
eventObject.newdescription = thisResponse; //New description entry
break;
}
}
return eventObject;
}
function createCalendarEvent(eventObject) {
//Get a calendar object by opening the calendar using the
//calendar id stored in the GLOBAL variable object
var calendar = CalendarApp.getCalendarById(GLOBAL.calendarId),
//The title for the event that will be created
title = eventObject.title,
//The start time and date of the event that will be created
startTime = moment(eventObject.startTime).toDate(),
//The end time and date of the event that will be created
endTime = moment(eventObject.endTime).toDate();
//an options object containing the description and guest list
//for the event that will be created
var comboDescription = eventObject.description+" "+eventObject.newdescription
var options = {
description : comboDescription,
guests : eventObject.email,
location: eventObject.location,
};
try {
//create a calendar event with given title, start time,
//end time, and description and guests stored in an
//options argument
var event = calendar.createEvent(title, startTime,
endTime, options)
} catch (e) {
//delete the guest property from the options variable,
//as an invalid email address with cause this method to
//throw an error.
delete options.guests
//create the event without including the guest
var event = calendar.createEvent(title, startTime,
endTime, options)
}
return event;
}
我是脚本编写的新手,一直在尝试将它们组合在一起,而无需购买扩展程序或使用 chrome 附加组件。
我不仅希望能够获取 Goggle 脚本表单回复,还希望能够获取表单回复电子表格的额外列(我在其中处理了不同列中的一些回复)并使用它来设置日历约会,其中描述是操作数据的列(不是数据的原始响应列)。在下面的示例中,我希望日历描述是 [Combo Description] 列,它表示两个表单响应的 arrayformula 组合:[Event Description] 和 [New Description],每个表单响应都出现在定义的日历中。
这是我尝试修改的示例,它是我尝试做的更详细内容的简化版本。
我的示例表单在这里 https://docs.google.com/forms/d/1EcafKYmstMiPcIhYpEsnvmf47yyeWNiYZIyxr93QkPU/edit?usp=sharing
支持的 google 电子表格在这里: https://docs.google.com/spreadsheets/d/1db6n-d88KrCWKXMuaFYYOU75pNOAysqwBuc7aORkmKE/edit?usp=sharing
我正在使用来自以下网站的脚本的修改版本: http://www.jessespevack.com/blog/2016/2/9/turn-a-google-form-response-into-a-calendar-event
这是 my/his 脚本的副本:
//Load the Moment.js library once.
var moment = Moment.load();
var GLOBAL = {
//the id of the form we will use to create calendar events
formId : "1EcafKYmstMiPcIhYpEsnvmf47yyeWNiYZIyxr93QkPU",
//the id of the calendar we will create events on
calendarId : "81hoju2sgoldcjom4888opngk0@group.calendar.google.com",
//a mapping of form item titles to sections of the calendar event
formMap : {
eventTitle: "Event Title",
startTime : "Event Date and Start Time",
endTime: "Event Date and End Time",
description: "Event Description", // Tried the following: + , & concate col[6]:which didn't throw an error but didn't make an appointment either
location: "Event Location",
email: "Add Guests",
},
}
function onFormSubmit() {
var eventObject = getFormResponse();
var event = createCalendarEvent(eventObject);
}
function getFormResponse() {
// Get a form object by opening the form using the
// form id stored in the GLOBAL variable object
var form = FormApp.openById(GLOBAL.formId),
//Get all responses from the form.
//This method returns an array of form responses
responses = form.getResponses(),
//find the length of the responses array
length = responses.length,
//find the index of the most recent form response
//since arrays are zero indexed, the last response
//is the total number of responses minus one
lastResponse = responses[length-1], // The -1 goes after length
//get an array of responses to every question item
//within the form for which the respondent provided an answer
itemResponses = lastResponse.getItemResponses() // Took a comma off here
//create an empty object to store data from the last
//form response
//that will be used to create a calendar event
eventObject = {};
//Loop through each item response in the item response array
for (var i = 0, x = itemResponses.length; i<x; i++) {
//Get the title of the form item being iterated on
var thisItem = itemResponses[i].getItem().getTitle(),
//get the submitted response to the form item being
//iterated on
thisResponse = itemResponses[i].getResponse();
//based on the form question title, map the response of the
//item being iterated on into our eventObject variable
//use the GLOBAL variable formMap sub object to match
//form question titles to property keys in the event object
switch (thisItem) {
case GLOBAL.formMap.eventTitle:
eventObject.title = thisResponse;
break;
case GLOBAL.formMap.startTime:
eventObject.startTime = thisResponse;
break;
case GLOBAL.formMap.endTime:
eventObject.endTime = thisResponse;
break;
case GLOBAL.formMap.description:
eventObject.description = thisResponse;
break;
case GLOBAL.formMap.location:
eventObject.location = thisResponse;
break;
case GLOBAL.formMap.email:
eventObject.email = thisResponse;
break;
}
}
return eventObject;
}
function createCalendarEvent(eventObject) {
//Get a calendar object by opening the calendar using the
//calendar id stored in the GLOBAL variable object
var calendar = CalendarApp.getCalendarById(GLOBAL.calendarId),
//The title for the event that will be created
title = eventObject.title,
//The start time and date of the event that will be created
startTime = moment(eventObject.startTime).toDate(),
//The end time and date of the event that will be created
endTime = moment(eventObject.endTime).toDate();
//an options object containing the description and guest list
//for the event that will be created
var options = {
description : eventObject.description,
guests : eventObject.email,
location: eventObject.location,
};
try {
//create a calendar event with given title, start time,
//end time, and description and guests stored in an
//options argument
var event = calendar.createEvent(title, startTime,
endTime, options)
} catch (e) {
//delete the guest property from the options variable,
//as an invalid email address with cause this method to
//throw an error.
delete options.guests
//create the event without including the guest
var event = calendar.createEvent(title, startTime,
endTime, options)
}
return event;
Logger.log(event);
}
/***
For later to make the endDate be a fixed 2hr appointment
var submittedDate = new Date(userSubmission);
var parsedDate = Date.parse(submittedDate);
var endDate = new Date(parsedDate + 120000);
**/
请就如何将表格电子表格的额外列添加到日历建议中提出任何提示或建议,我们将不胜感激!!!
首先,因为您只是组合了 New Description
和 Event Description
项目来创建新的描述。您不需要使用数组公式和 google 工作表来组合它。您可以在应用程序脚本本身中执行此操作。
修改:
1) 您必须从表单中检索这个新项目(新描述)。您将修改您的 formmap 对象,以包含这个新项目
formMap : {
eventTitle: "Event Title",
startTime : "Event Date and Start Time",
endTime: "Event Date and End Time",
description: "Event Description", // Tried the following: + , & concate col[6]:which didn't throw an error but didn't make an appointment either
location: "Event Location",
email: "Add Guests",
newdescription : "New Description" //New entery
}
2) 您将获得用户在 switch case 语句中创建的新条目,如下所示:
switch (thisItem) {
case GLOBAL.formMap.eventTitle:
eventObject.title = thisResponse;
break;
case GLOBAL.formMap.startTime:
eventObject.startTime = thisResponse;
break;
case GLOBAL.formMap.endTime:
eventObject.endTime = thisResponse;
break;
case GLOBAL.formMap.description:
eventObject.description = thisResponse;
break;
case GLOBAL.formMap.location:
eventObject.location = thisResponse;
break;
case GLOBAL.formMap.email:
eventObject.email = thisResponse;
break;
case GLOBAL.formMap.newdescription:
eventObject.newdescription = thisResponse; //New description entry
break;
}
3) 然后要制作组合描述,您只需加入字符串描述和新描述。
var comboDescription = eventObject.description+" "+eventObject.newdescription
并使用这个新的 comboDescription 创建您的日历事件。
var comboDescription = eventObject.description+" "+eventObject.newdescription
var options = {
description : comboDescription,
guests : eventObject.email,
location: eventObject.location,
};
完成所有这些修改后,您的最终代码将是:
var GLOBAL = {
//the id of the form we will use to create calendar events
formId : "1EcafKYmstMiPcIhYpEsnvmf47yyeWNiYZIyxr93QkPU",
//the id of the calendar we will create events on
calendarId : "81hoju2sgoldcjom4888opngk0@group.calendar.google.com",
//a mapping of form item titles to sections of the calendar event
formMap : {
eventTitle: "Event Title",
startTime : "Event Date and Start Time",
endTime: "Event Date and End Time",
description: "Event Description", // Tried the following: + , & concate col[6]:which didn't throw an error but didn't make an appointment either
location: "Event Location",
email: "Add Guests",
newdescription : "New Description" //New entery
},
}
function onFormSubmit() {
var eventObject = getFormResponse();
var event = createCalendarEvent(eventObject);
}
function getFormResponse() {
// Get a form object by opening the form using the
// form id stored in the GLOBAL variable object
var form = FormApp.openById(GLOBAL.formId),
//Get all responses from the form.
//This method returns an array of form responses
responses = form.getResponses(),
//find the length of the responses array
length = responses.length,
//find the index of the most recent form response
//since arrays are zero indexed, the last response
//is the total number of responses minus one
lastResponse = responses[length-1], // The -1 goes after length
//get an array of responses to every question item
//within the form for which the respondent provided an answer
itemResponses = lastResponse.getItemResponses() // Took a comma off here
//create an empty object to store data from the last
//form response
//that will be used to create a calendar event
eventObject = {};
//Loop through each item response in the item response array
for (var i = 0, x = itemResponses.length; i<x; i++) {
//Get the title of the form item being iterated on
var thisItem = itemResponses[i].getItem().getTitle(),
//get the submitted response to the form item being
//iterated on
thisResponse = itemResponses[i].getResponse();
//based on the form question title, map the response of the
//item being iterated on into our eventObject variable
//use the GLOBAL variable formMap sub object to match
//form question titles to property keys in the event object
switch (thisItem) {
case GLOBAL.formMap.eventTitle:
eventObject.title = thisResponse;
break;
case GLOBAL.formMap.startTime:
eventObject.startTime = thisResponse;
break;
case GLOBAL.formMap.endTime:
eventObject.endTime = thisResponse;
break;
case GLOBAL.formMap.description:
eventObject.description = thisResponse;
break;
case GLOBAL.formMap.location:
eventObject.location = thisResponse;
break;
case GLOBAL.formMap.email:
eventObject.email = thisResponse;
break;
case GLOBAL.formMap.newdescription:
eventObject.newdescription = thisResponse; //New description entry
break;
}
}
return eventObject;
}
function createCalendarEvent(eventObject) {
//Get a calendar object by opening the calendar using the
//calendar id stored in the GLOBAL variable object
var calendar = CalendarApp.getCalendarById(GLOBAL.calendarId),
//The title for the event that will be created
title = eventObject.title,
//The start time and date of the event that will be created
startTime = moment(eventObject.startTime).toDate(),
//The end time and date of the event that will be created
endTime = moment(eventObject.endTime).toDate();
//an options object containing the description and guest list
//for the event that will be created
var comboDescription = eventObject.description+" "+eventObject.newdescription
var options = {
description : comboDescription,
guests : eventObject.email,
location: eventObject.location,
};
try {
//create a calendar event with given title, start time,
//end time, and description and guests stored in an
//options argument
var event = calendar.createEvent(title, startTime,
endTime, options)
} catch (e) {
//delete the guest property from the options variable,
//as an invalid email address with cause this method to
//throw an error.
delete options.guests
//create the event without including the guest
var event = calendar.createEvent(title, startTime,
endTime, options)
}
return event;
}