Google Form: setAcceptingResponses() fails with copied form

59 views
Skip to first unread message

Brian Gray

unread,
Apr 16, 2024, 8:30:52 AM4/16/24
to Google Apps Script Community
I have used GAS for several years to make a copy of a Form, modify it, and then make it available for use via the published URL.  I do this once per year.

This year, when I ran the code, the form is copied and modified as i the past, but when I use the published URL, I am told that the form has not been published.

I added a call to setAcceptingResponses(true), but that causes an error ("Exception: Failed to edit the form. Please wait and try again.").

function copyForm() {
  let ts = Utilities.formatDate(new Date(),"CDT", "yyyy-MM-dd-HH:mm:ss");

  var templateForm = DriveApp.getFileById(TEMPLATE_FORM_ID);
  var destFolder = DriveApp.getFolderById(DEST_FOLDER);

  let newFormFile = templateForm.makeCopy("Copy Foo-" + ts, destFolder)
  newFormFile.moveTo(destFolder)

  Logger.log("newFormFile ID = " + newFormFile.getId())
  let newForm = FormApp.openById(newFormFile.getId())

  newForm.setTitle("Copy Foo-" + ts)
    .setDescription("Copy Foo-" + ts)
    .setConfirmationMessage('Thanks for responding!')
    .setAllowResponseEdits(true)
    .setRequireLogin(true)
    .setCollectEmail(true)
    .setLimitOneResponsePerUser(true)
    .setPublishingSummary(false)
    .setShowLinkToRespondAgain(false)


  Logger.log(newForm.getPublishedUrl())

  // this call fails with error: "Exception: Failed to edit the form. Please wait and try again."
  newForm.setAcceptingResponses(true)

}


When I run the sample code that creates a new new form from scratch, it works as expected. I could build my forms from scratch, but I don't see a way to set some specific fields. I want to:
  • set the Collect Email Addresses field to Verify (so that responders see their email address and have to check the box to confirm)
  • set the list of allowed responders to a Google Group
Are these settings possibile in GAS?


Reply all
Reply to author
Forward
0 new messages