Reputation: 427
I'm using data validation in google sheets to work like a button to call a function. One option is to reset my spreadsheet (call reset() function) so it clears all the data. Another option is to save my spreadsheet (call saveAs() function). When I run reset() and saveAs(), both functions work properly. My onEdit function works as well and calls reset() and saveAs() depending on which selection I make in the spreadsheet cell.
My problem is the saveAs() function does not complete only when it is called from the onEdit() function. When called on it's own, it is fine, but when called from onEdit() it gets hung up at this line
var parentFolder = DriveApp.getFileById(thisFileId).getParents().next();
Here is the entire function
function saveAs(){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var d = new Date();
var thisFileId = SpreadsheetApp.getActive().getId();
var parentFolder = DriveApp.getFileById(thisFileId).getParents().next();
DriveApp.getFileById(sheet.getId()).makeCopy(d+"", parentFolder);
}
I would be very grateful for any explanations and/or solutions!
Thank you.
Upvotes: 0
Views: 134
Reputation: 427
It turns out the reason it was getting hung up is because the onEdit apps script trigger is a "simple trigger" as opposed to an "installable trigger". This means it does not have access to change files and directories, which is why it seemed like it was getting hung up when the DriveApp class was called.
In order to fix this I created an installable onEdit-like trigger to call my saveAs function and it worked!
Upvotes: 1