Google Form-side form trigger not firing - google-apps-script

This is a trigger and script coded directly into the form rather than on the spreadsheet that gets the form, I'm not sure if that is why this isn't working or not.
The trigger is set:
Owned by: Me
Last Run: null
Deployment: Head
Event: From Form-On form submit
Function: sendEmailFromSheet
Things I've tried: having the person who originally owned the form create a trigger yesterday, me create one today.
Filling out the form DOES result in the answers on the result spreadsheet, but it doesn't fire this onSubmitForm trigger, and I have no idea why. Again, it isn't that the function is failing but that it isn't firing at all.

Given that the function label is 'sendEmailFromSheet' then I suspect that its waiting for the sheet to receive data. But because the function is in the form it will never run because your trigger references the form and not the sheet.
If you can show us the code behind it then we might could tell you better. But without knowing that part then I think that is the mostly reason.

Related

onChange trigger is not firing sometimes

onChange trigger may not fire under the following conditions. Do you know the cause and the remedy?
Check the checkbox in the spreadsheet
Select Spreadsheet list
I just created it like this.
Create an empty spreadsheet
Rewriting the default code
function myFunction (event) {
event.source.getActiveSheet().getActiveRange().setValue(false);
}
Create onChange trigger
Create a checkbox in cell A1
Check the check box (about once in 10 times, the process is not executed and it is not displayed in Executions)
Onchange not firing
Yeah creating an empty spreadsheet is kind of a problem since the new container won't have a trigger inside of it's project. There are no events that fire upon the editing of script in the script editor. Yeah creating an onChange trigger that's not covered either I would not hold my breath on that one. But if you must have it then make it a feature request. That's enough for me for one question.

'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 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.

How to get onFormSubmit to trigger automatically?

The "fix" (test_onformsubmit) code you gave, I have to manually run it every time there is new data in the spreadsheet. I was wanting it to automatically send the pdf to email when Form is submitted. Is there a way? Because the manual way runs the code exactly like its supposed to, but I want this as an automatic event so I don't have to do anything.
See parent thread of original problem/question
Read Understanding Triggers. This function is an Installable Trigger, so you need to set it up to run when a form is submitted. It's easy - I would have thought a Forms tutorial would have walked through it.
In the Script Editor:
Choose Edit > Current project's triggers. You see a panel with the message No triggers set up. Click here to add one now.
Click the link.
Under Run, select the function you want executed by the trigger. (That's onFormSubmit(), in this case.)
Under Events, select From Spreadsheet.
From the next drop-down list, select On form submit.
Click Save.
From this point on, the function will be triggered whenever a form is submitted to the spreadsheet.
If you plan to share your script, each recipient will need to repeat these steps.
As an aside, you should change the email setting in your script, so it will work for ANYONE.
var email_address = Session.getActiveUser().getEmail();

How to stop duplicate emails from active users?

I need a little guidance!
I have created a simple script for a Google Spreadsheet that is designed to email a user when a specific criteria is met and mark that row as "Emailed"; it runs on the onEdit trigger and works great.
However, if more than one trigger enabled user has the sheet open at the same time it will send the same email from each account.
I tried using:
function onChange(e) {
if (ROW HASN'T BEEN EMAILED ALREADY) {
if (3 CELLS IN A ROW HAVE CONTENT) {
if (Session.getActiveUser().getEmail() == e.user.getUserLoginId()) {
SEND THE EMAIL
MARK ROW AS EMAILED
}
}
}
}
So that only the user that made the change sends the email, however, all users still send the email. I have compared the values Session.getActiveUser().getEmail() and e.user.getUserLoginId() produce manually and in theory it should work ... though clearly I am doing something wrong!
Thanks.
This is a bit of a confusing topic but I believing this is functioning correctly.
Here are some details.
In the onChange(e) function, e.user will always be the person that "owns" the document. Look towards the bottom of this page on events in the document. In essence, you cannot figure out which user's change caused the trigger to fire.
When there are two users each with a trigger on the onEdit event, then both of the triggers will run each time (essentially the function runs twice) even if only one of the user has the spreadsheet open. However, per #1 you can't within the trigger function run figure out which user's change caused the onEdit event
You'll have to rethink your workflow a bit, perhaps as a timed trigger that checks every hour for people to be emailed. Another option is to only have one trigger that runs as the document owner and you can perform the checking logic there. Hope this makes sense.