ruslan4kad
ruslan4kad

Reputation: 25

google script - entire form delete

I want to send a form in Email to a group of 15 users. The form would contain just two questions one radial button with a pre-set long code and another one is yes and no. So creating form and emailing the form by doing it within Google Script is NOT the question here.

However, once users submit I want this form to be deleted. I know I can just do isAcceptingResponses() to false and let these old forms dust in my Google Drive. However, if I do that I will keep collecting irrelevant forms in my Google Drive. Is there anyway to destroy a form? or what would you suggest?

Here is an example of creating form as per Google developers manual https://developers.google.com/apps-script/reference/forms/:

function myCreateForm() {
var form = FormApp.create('Form Autocreaticus');
var item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?');
item.setChoices([
        item.createChoice('Ketchup'),
        item.createChoice('Mustard'),
        item.createChoice('Relish')
    ]);
form.addMultipleChoiceItem()
    .setTitle('Do you prefer cats or dogs?')
    .setChoiceValues(['Cats','Dogs'])
    .showOtherOption(true);
form.addGridItem()
    .setTitle('Rate your interests')
    .setRows(['Cars', 'Computers', 'Celebrities'])
    .setColumns(['Boring', 'So-so', 'Interesting']);

Logger.log('Editor URL: ' + form.getId());

 return form.getId()  //so I can later use for my myDeleteForm().
}


    function myDeleteForm() {    //myDeleteForm(formID) {
  var formID = '1utQdu9EsuQFgMKNbP5Hjm68fxpP-_vKrBNNXL8jsOZo';
  DriveApp.getFileById(formID).setTrashed(true);
}

*This code was changed to accommodate the functionality. Thank you!

Upvotes: 2

Views: 2637

Answers (1)

axwege
axwege

Reputation: 86

To delete the file itself you may need to use the DriveApp. The methods you found only seem to remove/change settings or reponses.

This deletes:

function myDeleteForm() {    
    var formID = '1utQdu9EsuQFgMKNbP5Hjm68fxpP-_vKrBNNXL8jsOZo';
    DriveApp.getFileById(formID).setTrashed(true);
}

Upvotes: 3

Related Questions