See my function below. I have run this code successfully multiple times. I set up a trigger and it ran a couple of times as well. I started feeling pretty good about it so I wanted to start using this function on other reports. I set it up on at least 2 other files and they ran successfully manual and with triggers twice before failing. My original file was running this code for over a month with a trigger and didn't fail once until the other files experience it. Ironically it was all on 10/29/19 so I don't know if google made some changes. I don't know if its app script related or I could refine my code to get it to work.
I keep getting this error: Document 1eQ0uewvBDHVu66fydr76BHqtRJiGUkxtVAVFrkvRQR8 is missing (perhaps it was deleted, or you don't have read access?). Of course for each file and each time that I run the function, the file id changes since I am grabbing a new report from my email each day. So im assuming that I can use some changes to the bolded section of code below..
function getCSV() {
var threads = GmailApp.search('in:inbox from:"jreport_noreply@datapipe.mediaspectrum.net" subject:"Open SRs"');
var messages = threads[0].getMessages();
var len = messages.length;
var message=messages[len-1] //get last message
var attachments = message.getAttachments(); // Get attachment of first message
**var xlsxBlob = attachments[0]; // Is supposes that attachments[0] is the blob of xlsx file.
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlsxBlob).id;
var sheet = SpreadsheetApp.openById(convertedSpreadsheetId).getSheets()[0]; // There is the data in 1st tab.
var data = sheet.getDataRange().getValues();
Drive.Files.remove(convertedSpreadsheetId); // Remove the converted file.**
var sheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/18vpXXAuuIfJqww8EoL07dqHSGGHaV3IGRMUCcJz1t40/").getSheetByName("rawdata");
sheet.clearContents();
var range = sheet.getRange(1, 1, data.length, data[0].length);
range.setValues(data);
}