var sourceSpreadsheetID = "xxx";
var sourceWorksheetName = "xxx";
var targetSpreadsheetID = "yyy";
var targetWorksheetName = "yyy";
function importData() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
var thisData = thisSpreadsheet.getRangeByName("zzz");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
I ran the above code and it worked perfectly for two days (it ran every 6 hours through a trigger) but suddenly, it stopped working and I keep on getting an error "You do not have permission to access the requested document". The source sheet and target sheet are in a shared drive, hence, there is mutual access for both sheets.
I am running the same script for a different pair of sheets, in the same team drive, and it is working perfectly.
I tried the following suggestions but to no avail: