'Apps Script - Cannot retrieve the next object: iterator has reached the end
When I run a script (UPDATE_PRODUCT_DATA) through the editor it runs fine. When it is run through a Trigger it fails. It is failing at getFilesByName – but the file “IJO 12.05.22.xlsm “ is in my Drive.
Execution Log:
Info
IJO 12.05.22.xlsm
May 12, 2022, 10:05:54 PM
Error
Exception: Cannot retrieve the next object: iterator has reached the end. at
convertExcel2Sheets(convertExcel2Sheets:3:60) at UPDATE_PRODUCT_DATA(UPDATE_PRODUCT_DATA:37:5)
Part of UPDATE_PRODUCT_DATA that calls ConvertExcel2Sheets:
//Get todays JO and convert it to Sheets & open it
joFile = SS2Name + " " + now + ".xlsm";
Logger.log(joFile);
convertExcel2Sheets(joFile,SS2Name); //LINE 37 ERROR HERE
ConvertExcel2Sheets script (LINE 3 highlighted):
function convertExcel2Sheets(sourcefileName,convertedfileName){
var sourceFile = DriveApp.getFilesByName(sourcefileName).next(); //LINE 3 ERROR HERE
var sourcefileId = sourceFile.getId();
var sourcefileBlob = sourceFile.getBlob();
var sourcefolderId = Drive.Files.get(sourcefileId).parents[0].id;
var convertedfileType = MimeType.GOOGLE_SHEETS;
var convertedFile = {title: convertedfileName, mimeType: convertedfileType, parents: [{id: sourcefolderId}]};
Drive.Files.insert(convertedFile, sourcefileBlob, {convert: true});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|