Issue with Google Scripts Time-Based Trigger in Sheets addon always Failing - google-apps-script

I'm having an issues with a "Sheets Addon" i am working on. I know how to create triggers in a normal script, but what I'm trying to do is create a trigger within an Addon that will call back to a function within that same addon. I want this to be a timed based trigger, every 1 or 2 hrs as the options.
If I create the trigger via sheets scripts, it all works fine, but using the same exact code for the addon.. it fails 100% of the time, but with no specific error, or at least not that i can get to easily.
I'm assuming there is something different to be add to the code to make a new trigger code work within an addon, but not sure what it is. any help would be greatly appreciated.
EDIT 12/4/2019::
example snippet... if i place this into the sheets script, and run it (from the sheet and not from the addon) it works fine. The trigger gets added and calls to the function with no issues. However when i run it from the sheet via the addon, the trigger still gets created but error our when processing.
function testCreateTrigger() {
ScriptApp.newTrigger('testRunTrigger')
.timeBased()
.everyHours(1)
.create();
}
One thing i'm noticing is that the Trigger for the sheet (non-addon) is created with Project name, Deployment, Event, Function ... all populated, but when i run it via the addon, the Deployment is blank.
Also installed the google salesforce addon which has a schedule feature which adds as a trigger, but that addon somehow creates the trigger with a "Blank" value for Project, Deployment, and Function ..but still knows what function within the addon/script to call to process. I think that's what I'm missing, how to create a trigger, from a function, within an addon.

Related

'Exception: Action not allowed' when attempting to programmatically add an Installable Trigger

I have a template google sheet that our company duplicates for every project.
The final result I want is to have an onEdit trigger that does a POST request. I actually already have this working. The issue stems from this: This trigger cannot be a simple trigger, it must be an installable trigger because according to Google's restrictions, simple triggers cannot make external requests, but installable triggers can. Again, all of that works, I just have to set up the installable trigger manually.
As I mentioned, this is a template document, so creating a new installable trigger manually every time it is duplicated is a real pain. I want to improve my UX by having it done automatically. Now the API documentation DOES detail how you can do this programmatically right here. So it definitely should be possible if I'm reading this correctly.
In order to have this trigger automatically created, I, of course, must use another trigger. In this case, it MUST be a simple trigger or we're back with the same issue.
So I added this onOpen() simple trigger function to my code: (convertAlias is the name of the function to run when the onEdit trigger activates)
function onOpen() {
if (ScriptApp.getProjectTriggers().length == 0) {
ScriptApp.newTrigger('convertAlias')
.forSpreadsheet(SpreadsheetApp.getActive().getSheetId())
.onEdit()
.create()
}
}
When I open the document though, I get no results. The stack logging shows the error as Exception: Action not allowed. The error specifically originates from the create() call.
I thought that maybe there was some issue with creating an installable trigger from a simple trigger so I went for the next best thing, a button. I added a button to my spreadsheet that was linked to the same code as a "generateTrigger()" function. Pushing that actually DID bring up the Authorization screen, which is what is expected. But then after authorizing my account, it then goes on to report the same Exception: Action not allowed. After that initial authorization, it does not ask me again and automatically goes to that error. I get the same results from running the function manually in the editor.
Is there any way I can make this installable trigger happen with any sort of automation? Is this an issue with my code, a permissions issue, or something else?
Thanks
It appears I should have just been passing the sheet and not the ID? Doesn't seem right but getting rid of getSheetId() made it work!

google triggers stopped executing

I have been using a number of triggers based on form submission to a google sheet. Since yesterday the triggers have stopped working.
I have
unlinked and re-linked the form and sheet.
created a new response sheet.
recreated my scripts,
tried macros ( its a simple operation to sort the google sheet responses and send the top most response to another sheet )
the form submit trigger doesnt work. so to test I setup time based triggers. they seemed to work but stopped at 5 am this morning.
I can run the script manually and works fine but triggers do not run.
There was nothing in the logs. each trigger just stopped firing
Can anyone advise ?
Many thanks
I'd like to confirm the issue
Problem
installable trigger onFormSubmit from GoogleSheet stopped executing.
installable trigger onMinute from the same Spreadsheet still working and showing logs.
Logs are empty here:
https://script.google.com/home/projects/PROJECT/executions
Solution?
My attempts to resolve the issue:
Delete and create trigger again
Change the source code
Create 2 same triggers.
Possible other tests:
Create trigger from another account
Create a trigger with no code to test if it could execute at all.
Conclusion
In the end, one of my newly created triggers started the execution again.
I do not know what fixed the problem: changing the function text OR creating/deleting triggers OR some external fix on the Google side.
If some have more issues, please report the issue here:
https://issuetracker.google.com/savedsearches/566222

onOpen() function running fine when triggered manually within script window but not via onOpen trigger

I created a Google Script for work (that I don't want to share here) and that works perfectly fine with one onOpen() trigger.
Since I was working on that script on a personal Spreadsheet for testing purposes, I eventually moved it to the real Google Sheet it was meant to run on from the beginning and while the onOpen() function still works properly by being called via "Run function" or even "Debug function", the trigger is not fired, and I'm not getting any log or debug info that could potentially help me.
I deleted and recreated the trigger several times as I saw that this was a known work-around for the issue, but it's not changing anything. When I then go check "Current triggers", I see that it hasn't fired even once and I'm clueless as to what's causing this issue...
While not wanting to give away the whole script since it works anyway, I'm providing the code for my triggered function, even though it didn't change since it last worked successfully on my test spreadsheet:
function onOpen()
{
var aSheet = SpreadsheetApp.getActiveSheet();
var emailRow = 2;
var emailColumn = 3;
for(; !aSheet.getRange(emailRow, emailColumn).isBlank(); emailRow++)
{
aSheet.getRange(emailRow, 19).setValue(matchNPandCIO(emailColumn, emailRow));
}
}
The only thing I can add and that's probably not related is that the spreadsheet on which I now have the script trying to run had an ownership change today and that I'm now its owner. I'm running out of ideas and things to try...
And yes, I also made sure that I gave the script the required authorizations it needs (done after creating the trigger).
Simple triggers like onOpen run anonymously so if matchNPandCIO calls methods that require authorization to run it will fail.
The alternative is to use an installable trigger.
Related
Google Doc onOpen will not fire when spreadsheet is accessed

Google Apps Script onEdit() trigger not executing

I have been implementing a spreadsheet for about a year and a half now that constantly runs a number of trigger based GAS functions to check data, send emails based on that data, and update a staff calendar.
All of the time driven triggers are executing normally. I have not had an issue with them. However, the spreadsheet driven triggers (onEdit, onChange) are not working at all. I left work for a two week vacation and I did not change the script at all. When I came back, it no longer worked.
I deleted the trigger, recreated it, and switched between onEdit and onChange; the trigger will still not fire. The function that is triggered on edit is dependent on the event for it to execute properly. I test ran the function outside of the trigger and it failed where I expected it to (where the event dependant variables are) so there was no surprise there.
As far as I can tell, the spreadsheet driven triggers just won't fire at all. Does anyone know of any issues on Google's end, are spreadsheet driven triggers working for any of you guys? As far as I can tell the trigger just stopped working all together.
If I explicitly nest my function inside the onEdit() function in the script, it will execute, it won't if I just create a trigger, however it throws an error saying that the script does not have the permissions to execute MailApp.sendEmail() even though the app is already authorized to send emails as me.
Even more interesting, the functions executed with time driven triggers are still able to send emails and update my calendar.
It seems like the spreadsheet driven triggers have quit working all together.
Just to be clear I did not make the mistake of naming my function onEdit or onChange.

Can't Locate/Delete an Installable Trigger

I installed a form submit trigger for my project using ScriptApp around the beginning of May. The trigger has worked just fine however I now wish to uninstall the trigger and am running into problems. When I try to view all my current project triggers (Resources > Current project triggers), it returns that there are no associated triggers. Also when I try to run (Resources > All your triggers) it returns that there are no triggers shown.
I'd like to believe that this is the case, that the trigger in question has been somehow deleted but I don't believe that it is. To make sure the trigger didn't run, I de-authorized the script to run from my google account settings.
My suspicions that the trigger was not deleted were confirmed when I received a "Summary of failures for Google Apps Script: Form Processing Script" which told me my script had failed 3 times because, "Authorization is required to perform that action."
These failure e-mails also contain a statement, "To configure the triggers for this script, or change your setting for receiving future failure notifications, click here." When I click on the link, there are no triggers shown...
Here's a look at the code i used to install the trigger:
function formSubmitTriggerInstall() {
var formID = '1rOikLDUAqMWCB0ktjWzFE0oB6LmOHvXuzPAqyq0XLwE';
ScriptApp.newTrigger('processForm')
.forForm(formID)
.onFormSubmit()
.create();
}
I have also tried to locate the trigger using ScriptApp but to no avail.
Does anyone have any suggestions on how I can eliminate this trigger or get the associated trigger ID?
One other note, since I installed the trigger, the google developer's website and documentation went through a major face lift and some of the page content appears to be updated as well. Not sure that would affect my triggers though.
It was confirmed that this was a big and it was fixed by the apps script team.