I am currently working in a Google Education domain and I would like to automatically generate a Google Doc via an onSubmit trigger from a Google Form. I have a template file that I would like to copy and then replace fields (e.g., {{name}}) with responses from the form.
Upon submission, the template Google doc is successfully copied and renamed, but I cannot open the doc to replace the text fields.
var templateFile = DriveApp.getFileById(id);
var targetFolder = DriveApp.getFolderById(id);
var newDocName = title + "_" + name + "_" + submissionDate;
var newFile = templateFile.makeCopy(newDocName, targetFolder);
var newFileId = newFile.getId();
var doc = DocumentApp.openById(newFileId);
var body = doc.getBody();
The doc is copied and renamed, but throws an error at "DocumentApp.openById"
You do not have permission to call DocumentApp.openById. Required permissions: https://www.googleapis.com/auth/documents at onSubmit(Code:81)
I don't know why because I am the owner of both the form and the template!