In google app script, making a copy of a spreadsheet that contains a linked Form used to also copy the linked Form when you copied between two different Google free consumer accounts. That appears to no longer be the case.
In the example below, getFormUrl returns null. What is a work-around to copy the linked Form along with the Spreadsheet like it used to?
// from a 2nd google consumer account, get file by ID of a master
// spreadsheet in a different user account that contains a linked Form
var masterSpreadsheetFile = DriveApp.getFileById('1Jeh4b0BrF4qjogErZpd-bnnoVhLdRj2-hfwXy.....');
// make a copy of the master for this 2nd free google consumer account user
var copiedSpreadsheetFile = masterSpreadsheetFile.makeCopy('myCopiedSpreadsheet', 'MyFolder');
// set the name of the Copied linked Form
var copiedSpreadsheet = SpreadsheetApp.open(copiedSpreadsheetFile);
var copiedFormUrl = copiedSpreadsheet.getFormUrl(); // fails here
var copiedFormId = getIdFromUrl(copiedFormUrl);
var copiedFormFile = DriveApp.getFileById(copiedFormId);
copiedFormFile.setName('myNewCopiedForm');
enter code here
Copying a sheet via the GUI within the same user account DOES copy the linked Form.
I found the problem, there must have been some changes made to how permissions are handled for linked Forms. Previously the linked Form must have inherited the permissions of the spreadsheet it is linked to. Now those permissions need to be explicitly set on the form. So the simple solution was to go into the form, 'add collaborators' and set to 'Anyone who has the link can edit'.
With that change, when you make a copy of a spreadsheet between two different Google free consumer accounts, it will also copy the linked Form.
来源:https://stackoverflow.com/questions/33454803/copying-google-spreadsheet-no-longer-copies-linked-form