I would like a user to be able to tap a button in a sheet to install a trigger for a standalone script that will manage a couple of mail functions. I need this because I have a user that cannot follow instructions, and thus I cannot ensure they will create a trigger manually, properly.
I would like them to just open a Google Sheet, tap the button, approve what needs approving, then be good to go.
So, they need
- The 'main' function of my "amazingLabels" standalone Google Apps Script to trigger every minute.
- That must be installed by the amLabsInstallSheet Google Sheet. They have read access to both.
I have used this answer as the basis for what I'm trying to do, I haven't found anything better, the only thing I've changed is some names.
So, I have created my own standalone script amazingLabels and inside it is the following:
function doGet(e) {
createTrigger();
return ContentService.createTextOutput('success!');
}
function createTimeTrigger() {
UrlFetchApp.fetch('appUrlExec');
}
function createTrigger() {
var tr = ScriptApp.newTrigger('main');
tr.timeBased().everyMinutes(1).create();
}
function main() {
mainOne();
mainTwo();
};
Where appUrlExec
is the /exec link for this amazingLabels standalone script.
Now, I should be able to create a spreadsheet, which we'll call amazingLabelsInstaller with amazingLabels as a library, and inside the bound script for the spreadsheet call:
function testLib() {
amazingLabels.createTimeTrigger();
}
However I just cannot get it to install that trigger for the user to run every minute.
If I focus on any other function, it works. Ie. if I call 'main' directly with amazingLabels.main(); it will run that function.
What am I doing wrongly here? Is it the new trigger code?
I've tried every combination of deployment, from a Google Suite deployment, to a private account deployment. From running as myself, to running as the user. I've tried them as editors on both document or none (but it should work as viewers, right?), and with both script and sheet deployed or sheet not-deployed.
Any help would be appreciated, apologies if anything is unclear, here, happy to work through it in the comments.