user3347814
user3347814

Reputation: 1133

How to duplicate form using Google App Script

I have a Google Form that I need to duplicate. I want to create a different form for every person on my team (30+ people).

I've looked into the documentation and I could not find a method that duplicates the form.

This is what I want to do:

var template_form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var new_form = template_form.a_method_that_duplicates_the_form(); // Could not find this method
var new_form_id = new_form.getId();
... //and so on...

Is there any way to duplicate forms using Google App Script?

Upvotes: 1

Views: 2368

Answers (1)

Nikko J.
Nikko J.

Reputation: 5533

Form Service can only create, access, and modify Google Forms. In order to duplicate Forms, you have to use the Drive Service.

Here I created a code that duplicates a Form, change its Title and save it to a specific location in Drive:

function duplicateForm() {
  var templateformId = 'template form id here';
  var destFolder = DriveApp.getFolderById("destination folder id");
  var file = DriveApp.getFileById(templateformId).makeCopy("file name", destFolder);
  var fileId = file.getId()
}

Template Form:

enter image description here

Output:

enter image description here

References:

Upvotes: 9

Related Questions