Vito Alessandro I.
Vito Alessandro I.

Reputation: 1

Open a new Google Spreadsheet file from Google Form using script

I'm trying to save all the responses of a Google Form file (with an onSumbmit(e) function, based on a trigger) to a newly created spreadsheet, based on a template. Unfortunately my script stops working at this point:

var ID = "I put here the ID of the file template";
  
  var ss = SpreadsheetApp.open(DriveApp.getFileById(ID)); <-- Here it stopped

  ss.copy(name+"_"+date);

I really don't know why, but the scripts seems unable to open the template file and make a copy. I've also tried with a getFileByUrl, SpreadsheetApp.openById(ID) and SpreadsheetApp.openByUrl(URL), but nothing change!

I receive this error: You do not have permission to call openById

I've read here that maybe it's a policy change of Google but it's over 2 years ago. Maybe I'm doing something wrong?

Thanks to all!

Upvotes: 0

Views: 150

Answers (1)

Vito Alessandro I.
Vito Alessandro I.

Reputation: 1

Ok, I've done!

My script has this at the beginning:

/**
* @OnlyCurrentDoc
*/

And I misunderstand its meaning! I didn't understand that this code forces the script to work only on the active form. Without this code it works perfectly! Thanks to everyone!!!

Upvotes: 0

Related Questions