Google Scripting: Responding to Pivot Forms
I am completely new to google scripting language. I am following a tutorial ( http://www.jessespevack.com/blog/2016/2/9/turn-a-google-form-response-into-a-calendar-event ) trying to convert a vacation form response to a calendar event ... I'm trying to find a way to combine multiple fields into one attribute, but I couldn't find a way to achieve this.
The tutorial includes this section:
//a mapping of form item titles to sections of the
//calendar event
formMap : {
eventTitle : "",
startTime : "",
endTime: "",
description: "",
location: "",
email: "",
},
After each attribute ("eventTitle", "startTime", etc.) I need to provide the field name from my form ("First name", "Last name"), etc. between quotes. Using one field in each of them works fine, but I need to combine the two fields into some attributes (eg First Name + Last Name), but all the traditional methods I know of don't work.
Combining questions (like one name) is not an option as there is more data I need to collect.
Any help would be greatly appreciated!
Many thanks!
source to share
If I understand correctly, you have additional form elements / fields that you want to be included in the new event. However, since it createEvent()
has limited parameters - would you like to combine additional information about the form into one of the createEvent () parameters (for example, the "description" event)?
// Add the extra form fields into your form map
formMap : {
eventTitle : "",
startTime : "",
endTime: "",
firstName: "", //to be concatenated into description or other parameter
lastName: "", //to be concatenated into description or other parameter
description: "",
location: "",
email: "",
},
// Add the new form items/fields to the `switch` statement
function getFormResponse() {
var firstName, lastName;
...
for (var i = 0, x = itemResponses.length; i<x; i++) {
...
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.firstName:
firstName = thisResponse;
break;
case GLOBAL.formMap.lastName:
lastName = thisResponse;
break;
case GLOBAL.formMap.description:
eventObject.description = thisResponse;
break;
case GLOBAL.formMap.phone:
eventObject.phone = thisResponse;
break;
case GLOBAL.formMap.email:
eventObject.email = thisResponse;
break;
}
}
//Once form responses are assigned, concatenate multiple items to eventObject.description
eventObject.description += " with " + firstName + " " + lastName;
return eventObject;
}
Use Add assignment to combine form fields into one of createEvent () :
//Once form responses are assigned, concatenate multiple items to eventObject.description
eventObject.description += " with " + firstName + " " + lastName;
source to share