Google Apps Script Error: “You do not have permiss

2019-07-21 02:55发布

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.

0条回答
登录 后发表回答