I have a Spreadsheet and Apps Script in the background that is serving a function CONFIRM(cell)
. This function performs several actions in the background
Code that is causing trouble:
function convertPDF(docId){
const targetDir = "Redacted";
var sourceFile = DriveApp.getFileById(docId);
let blob = sourceFile.getBlob().getAs('application/pdf');
let docPDF = targetDir.createFile(blob);
let fileName = templateFile.getName().replace(".", "");
docPDF.setName(fileName + ".pdf");
let filePDF = docPDF.getId();
let mailContent = "Redacted
to: user,
subject: "Redacted "+diplomaId,
htmlBody: mailContent,
attachments: filePDF,
})
return "SENT";
}
THe problem is that I am getting an error:
Exception: You do not have permission to call DriveApp.getFileById. Required permissions: (https://www.googleapis.com/auth/drive.readonly || https://www.googleapis.com/auth/drive) (line 24).
Line 24:
var sourceFile = DriveApp.getFileById(docId);
I completely do not know what's the issue here. Script works fine when ran with data provided in the script, but when ran as a function, it does not work.