Forms requires login

450 views
Skip to first unread message

Scott Bennett

unread,
Nov 25, 2020, 11:01:55 PM11/25/20
to Google Apps Script Community
I am creating multiple forms.  I cannot seem to find what the problem is.  I just want to allow for people outside the organization to fill out the form.  We have the ability to do that manually, I just keep getting errors on GAS.  

This is the first part of the code where the error happens.  Before I typed these two things everything was working correctly.  
function createSurvey(){
 var ss = SpreadsheetApp.openByUrl('URL');
 var sheet = ss.getSheetByName('Sheet1');
 var lrow = sheet.getLastRow();
 var data = sheet.getRange(2,1,lrow,1).getValues();
 

for(var i = 0;i<1;i++){
  Logger.log(data[i]);
    var importSheets = ss.insertSheet(data[i][0]);
  
  var forms = FormApp.create(data[i][0]);
  forms.collectsEmail(false);  <- Throws an error.
  forms.requiresLogin(false);  <-Throws an error.  

Here is the error I keep getting.
 Exception: The parameters ((class)) don't match the method signature for FormApp.Form.collectsEmail.
    at createSurvey(Code:24:9)

Thanks for you help.

Scott Bennett


Fco. Javier Lledó Fuster

unread,
Nov 26, 2020, 12:15:50 AM11/26/20
to google-apps-sc...@googlegroups.com
Hi,

Maybe you need to use the method .setCollectEmail (https://developers.google.com/apps-script/reference/forms/form#setcollectemailcollect) to set it, the other method is to get it.

Can you test it?

I hope it helps!

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/23936ec3-c27c-43bc-a55e-edf29226547co%40googlegroups.com.

Adam Morris

unread,
Nov 26, 2020, 3:12:00 AM11/26/20
to google-apps-sc...@googlegroups.com
Hi Scott,

I wonder if they are failing with an error because you don't have the scopes set? According to the documentation, there isn't any reason they would fail, unless your script didn't have permission to use that form service.

What's the error you're getting? Are you using a manifest file?

Adam



Martin Molloy

unread,
Nov 26, 2020, 4:22:36 AM11/26/20
to google-apps-sc...@googlegroups.com
Javier is correct

collectsEmail() and requireLogin() do not take parameters. They return True or False.

You use them to ask questions about the current form - is it set to collect Email addresses? Does it require Login?

You need to use setCollectEmail and  setRequireLogin

Martin


Scott Bennett

unread,
Nov 26, 2020, 7:20:36 AM11/26/20
to google-apps-sc...@googlegroups.com
Thank you that was it.

Scott Bennett


Sent from my iPhone 

On Nov 26, 2020, at 3:22 AM, Martin Molloy <martin...@mtmomk.co.uk> wrote:



kle...@ritenourschools.org

unread,
Feb 8, 2021, 3:36:25 PM2/8/21
to Google Apps Script Community
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()
Boolean
Determines whether the form collects respondents' email addresses.

setCollectEmail(collect)
Form
Sets 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?
Reply all
Reply to author
Forward
0 new messages