When I manually create a form and turn collect email on, the form shows a notice that emails are being collected and the responders email shows up in my responses spreadsheet.
When I am creating my form with apps script the Forms documentation shows two methods:
https://developers.google.com/apps-script/reference/forms collectsEmail()BooleanDetermines whether the form collects respondents' email addresses.
setCollectEmail adds a question to your form for responder to enter their email. It is poorly verified. I am not interested in taking whatever a student decides to put in and comparing it to my roster.
function emailTesting() {
console.log('Begin emailTesting');
const ui = SpreadsheetApp.getUi();
const ss = SpreadsheetApp.getActiveSpreadsheet();
const newForm = FormApp.create('testEmailForm');
const formId = newForm.getId();
console.log('Form Id: ', formId);
try {
newForm.collectsEmail(true);
} catch (err) {
console.log('Caught for collectsEmail: err: ', err );
}
newForm.addTextItem().setTitle('Name');
newForm.addTextItem().setTitle('Place of Birth');
}
Caught for collectsEmail: err: { [Exception: The parameters ((class)) don't match the method signature for FormApp.Form.collectsEmail.] name: 'Exception' }
Lower case true is not very classy but I do not have any idea why it is not being accepted as a Boolean???? Any ideas?
I did find that if I set "collectsEmail:true," in the JSON style object it creates a form with the message "This form is automatically collecting email addresses for xxxxxxxxxxxxxxxx SCHOOL DISTRICT " and works just like I had created the form manually. I would never have figured this out - thank you pioneers and cut & paste.
const fileResource = {
title: qTitle,
description :qDesc,
confirmationMessage:qConfMsg,
collectsEmail:true, // this worked ! ! ! ! !
requireLogin:true, // worked limited to school district
// isQuiz:false, // did not set - did it in other ways
"parents": [{'id':parFldrId}],
mimeType: 'application/vnd.google-apps.form'
};
let dummyForm = Drive.Files.insert(fileResource);
let newForm = FormApp.openById(dummyForm.id);
Is there any other way to enable automatic collecting of the active user email on a form with apps script?