I'm completely new to the google scripting language. I've been following a tutorial (http://www.jessespevack.com/blog/2016/2/9/turn-a-google-form-response-into-a-calendar-event) trying to convert a leave form response to a calendar event. I'm trying to find a way to concatenate a number of fields into a single attribute, but I haven't been able to 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) it requires me to list a field name from my form ("First Name", "Last Name") etc between the quotes. Using one field in each works just fine, but I need to concatenate two fields into some attributes (such as "First Name" + "Last Name"), but all traditional methods I know of don't work.
Combining questions (ie a single name field) isn't an option as there's more data I need to collect.
Any help would be greatly appreciated!
Many thanks!
If I understand correctly, you have extra form items/fields that you want to include in a new event. However, since the createEvent() has limited parameters - you would like to combine extra form information into one of the createEvent() parameters (e.g, event "description")?
// 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 the Addition assignment to concat the form fields into one of the createEvent() parameters:
//Once form responses are assigned, concatenate multiple items to eventObject.description
eventObject.description += " with " + firstName + " " + lastName;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With