1

I am trying to use a Google Script that I found on GitHub. (It is Posted Below.) It is supposed to merge data from Google sheets into a Google Doc. However, when I try to run the script I get an error: "You do not have permission to call openById". I have researched the problem and the information is conflicting. But, I have tried the following:

  1. Manually run the function in script editor before adding the trigger to Google sheet.
  2. Authorized the script to access my Google Docs data.
  3. Set the triggers for the function to "On Form Submit"
  4. Added the script to my Google Sheet and ran it from the menu as instructed: Merge --> Fill Template

I continue to get the error. I see that there are other people having the same problem, but the answers provided so far have not solved the issue. Any help would be greatly appreciated.

function doMerge() {
  var selectedTemplateId = "1foobarfoobarfoobarfoobarfoobarfoobar";//Copy and paste the ID of the template document here (you can find this in the document's URL)

  var templateFile = DriveApp.getFileById(selectedTemplateId);
  var mergedFile = templateFile.makeCopy();//make a copy of the template file to use for the merged File.
  mergedFile.setName("filled_"+templateFile.getName());//give a custom name to the new file (otherwise it is called "copy of ...")
  var mergedDoc = DocumentApp.openById(mergedFile.getId());
  var bodyElement = mergedDoc.getBody();//the body of the merged document, which is at this point the same as the template doc.
  var bodyCopy = bodyElement.copy();//make a copy of the body

  bodyElement.clear();//clear the body of the mergedDoc so that we can write the new data in it.
Rubén
  • 34,714
  • 9
  • 70
  • 166
Ike
  • 109
  • 3
  • 10
  • Triggers run in a limited auth mode, so services that require authorization to run won't be allowed to run inside triggers. that's why you keep getting that error. check this other question where is explained with more detail: http://stackoverflow.com/questions/31258439/need-to-move-row-from-one-google-spreadsheet-to-a-completely-different-google-sp – Gerardo Jul 07 '15 at 23:49

0 Answers0