Last active
April 2, 2021 15:20
-
-
Save barrieroberts/4f5b016cb2562f6e860b8676cdb6a24a to your computer and use it in GitHub Desktop.
10-Create form & send PDF when form filled out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Standalone script to create Form | |
function createForm() { | |
const form = FormApp.create("Brochure request"); | |
form.setTitle('Brochure request'); | |
form.setCollectEmail(true); | |
} | |
//Stored in Google Form - i.e. bound to form | |
//Send brochure PDF when form filled out | |
function example101() { | |
//Get email | |
const form = FormApp.getActiveForm(); | |
const responses = form.getResponses(); | |
const latestResponse = responses[responses.length - 1]; | |
const emailAddress = latestResponse.getRespondentEmail(); | |
//Get Slides and create PDF | |
const brochure = DriveApp.getFileById('ADD YOUR FILE ID HERE') | |
.getAs(MimeType.PDF); | |
//Send PDF in email | |
MailApp.sendEmail(emailAddress, | |
'BROCHURE', | |
'Please find attached this year\'s brochure.', | |
{ | |
attachments: brochure, | |
name: 'Brochure 2021' | |
}) | |
} | |
function setUpTrigger() { | |
var form = FormApp.getActiveForm(); | |
ScriptApp.newTrigger('example101') | |
.forForm(form) | |
.onFormSubmit() | |
.create(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment