I have a Google form linked to a trigger. when an onSubmit event is triggered the I'm getting an empty response object
function setupTriggers() {
ScriptApp.newTrigger('onSubmit')
.forForm('1n78vh9LfdUBCdKY4hcMZXEyYZw7ZxdE689-ihhczPow')
.onFormSubmit()
.create();
}
function onSubmit(e) {
console.log(JSON.stringify(e));
}
Log
{"authMode":"FULL","response":{},"source":{},"triggerUid":"1655010400613789390"}
When a form is submitted the event gets triggered, but the event response is empty.
Am I missing any steps while configuring the trigger?
Try something like this:
function setupTriggers() {
ScriptApp.newTrigger('onMyFormSubmit').forForm(FormApp.getActiveForm()).onFormSubmit().create();
}
function onMyFormSubmit(e) {
console.log(JSON.stringify(e));
var formResponse = e.response;
var itemResponses = formResponse.getItemResponses();
itemResponses.forEach(r=>{
console.log('Id: %s\nType: %s\nTitle: %s\nResponse: %s\n',r.getItem().getId(),r.getItem().getType(),r.getItem().getTitle(),r.getResponse());
});
}
I just have two questions on my form and here is what the executions look like for that form:
Cloud logs
May 4, 2021, 3:39:39 PM Debug {"authMode":"FULL","response":{},"source":{},"triggerUid":"7825823049830695122"}
May 4, 2021, 3:39:39 PM Debug Id: 1518756049
Type: MULTIPLE_CHOICE
Title: COL1
Response: 6
May 4, 2021, 3:39:39 PM Debug Id: 1430799996
Type: MULTIPLE_CHOICE
Title: COL2
Response: 2
The response object is not empty. Using the below references you can still get your responses. But it would be a lot easier to get these if you would look at the onformSubmit trigger for the spreadsheet. It's event object is much more accessible.
Interface Item Methods
Class ItemResponse
Google Sheets Events
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