I previous asked on Stack Overflow how I could import data from another Google Sheet using Google Script without using Spreadsheet ID. Previous question and the answers, to which was answered and was working fine. Now it seems that Google has updated something which stops it from working and as such is spamming my inbox with failed to complete error emails.
I am now getting the following error:
Exception: Cannot retrieve the next object: iterator has reached the end. (line 2, file "Data Import")
'Data Import' is the name of my script file.
Not only that, when I try to run other scripts on the same sheet, unless I completely delete this script the others fail to run too.
Here's the code that was running perfectly but has now stopped.
var folder = DriveApp.getFoldersByName("SOURCE FOLDER NAME").next();
var file = folder.getFilesByName("SOURCE FILE NAME").next();
var sourceSpreadsheetID = file.getId();
var sourceWorksheetName = "SOURCE WORKSHEET NAME";
var targetSpreadsheetID = "TARGET FILE ID";
var targetWorksheetName = "TARGET WORKSHEET NAME";
function importData1() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
//var thisData = thisWorksheet.getDataRange();
var thisData = thisSpreadsheet.getRangeByName("A:Q");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
nextmethod. Are you expecting to get this on the first file? Checked that your file is indeed there to be found? - Raserhin