Tuesday 16 June 2020

Remove Google Form created during copy

The following Google Apps Script is designed to remove the Google Form that is created when copying the Response Sheet file in Google Drive. The script checks to see if the original file has a linked-Form before making a copy, after which it finds the new Form's Url and removes it.

The 'Spreadsheet App' is used to open the new file and get the Url of the Form (if there is one):
var formUrl = SpreadsheetApp.openById(newFileId).getFormUrl();
Next the 'Form App' opens the newly created Google Form and gets its Id:
var form = FormApp.openByUrl(formUrl);
var formId = form.getId();
With the Id we can perform the final 2 steps of un-linking the Google Form from the Response Sheet and then deleting it:
form.removeDestination();
DriveApp.getFileById(formId).setTrashed(true);

Remove Google Form created during copy.gs

No comments:

Post a Comment