I have a new Forms response spreadsheet that I'm trying to trigger off. I don't make changes (yet) to the default myFunction() method and try to add a trigger. The first field tries to auto-populate forever, spinning and spinning, while I get this error message:
You cannot create a trigger without a target function, please add functions to the attached script.
I've done some online searching, and there are very few similar issues out there, and zero solutions for me.
CodePudding user response:
Before creating a trigger either manually or programmatically you should save the Google Apps Script project.
Tip: Replace the default project name by something descriptive otherwise you might eventually end with a lot of "Untitled project".
One advantage of doing this programmatically from the script editor is that when clicking on the Run button if the script was not save at least one time it will prompt for the project name and save the project.
Resources
CodePudding user response:
ScriptApp.newTrigger("must have a function name here not a function declaration")
function imanoob(e) {
Logger.log(JSON.stringify(e));
e.source.toast('I am a noob');
}
Copy both functions into script editor and save them. Run the second one first and then edit any cell on any tab or sheet.
function createImANoobTrigger() {
if(ScriptApp.getProjectTriggers().filter(t => t.getHandlerFunction() == 'imanoob').length == 0) {
ScriptApp.newTrigger('imanoob').forSpreadsheet(SpreadsheetApp.getActive()).onEdit().create();
}
}