Overview
Im making a script for my google sheet.
I have a helper method which takes email for parameter (string) and then invites that email to google drives folder.
I also have edit() function which gets called whenever a field in Google Sheets is changed.
Problem:
When helper method is called by itself from Google Scripts it works fine and I get an invite. When helper method is triggered from edit() while im in google sheets, it doesn't go all the way through to send an invitation. It stops at while function which returns false:
var newFolder = DriveApp.getFoldersByName("New Folder");
Logger.log(newFolder.hasNext());
while(newFolder.hasNext()) { -> returns false while in google sheets
var folder = newFolder.next();
Logger.log("folder -> " + folder);
folder.addViewer(newPersonEmail);
}
What I tried:
Logger.log
shows that newFolder.hasNext()
returns false while script
gets called from edit()
function (when im making a change in google
sheets). But it returns true when I simply debug function in Google
scripts.