kartik
kartik

Reputation: 612

Fetch the data that was submitted in the google form (using OnFormSubmit trigger) with apps script

I created an apps script project for my google form, and added a trigger which has the following settigs -

and my Code.gs file has this code, which is supposed to execute when a new submission arrives -

function sendemail(e) {
  GmailApp.sendEmail("[email protected]","Hello there","This is a sample sentence.");
}

When I tested this trigger by submitting a new form, I received the test email successfully. Now instead of a static email ([email protected]) being used as the recipient of the email, I want it to be the value my user entered in the Email field in the form submission which triggered this function. So I want my code to look like -

function sendemail(e) {
  GmailApp.sendEmail("<email from form response>","Hello <name from the form>","This is a sample sentence.");
}

So if the trigger data is arriving in the e parameter in sendemail function, how do I get the data which was submitted? When I debugged JSON.stringify(e), I get {"authMode":"FULL","response":{},"source":{},"triggerUid":"12647267"}.

Is there any way I get the data that was submitted in the form in the function? Do I need to change any settings on my form or trigger to get the data? I've just started with Google Apps Script and am a bit confused on how should I do this... Any advice is appreciated! Thanks :)

Upvotes: 0

Views: 1177

Answers (1)

kartik
kartik

Reputation: 612

Solution by @Cooper in the comments


Try using the onFormSubmit trigger for the linked Spreadsheet. It;s event object contains namedValues and values.

Thanks @Cooper, it works perfectly now. Cheers!

Upvotes: 0

Related Questions