On form submit trigger expired? - google-apps-script

this is the first time I'm using triggers with Google App Scripts and I was really delighted about the possibility to send individualised mails to users who submit a form. But...
I created a form and an App Script from a sheet with the on form submit trigger. I gave all the permissions and tested it and everything worked fine. Well... two weeks later we posted the link to the form. I expected everything to work fine, since I didn't read anything about an expiry date or something like that for triggers. But after a while - some users already submitted the form I realised the script didn't run (there were no automated Mails send). I tested it by submitting the form by myself - it didn't work. I checked all permissions and the trigger - everything looked fine. I decided to delete the trigger and create it again - exactly the same trigger (since there are not a lot of different options I'm pretty sure it's exactly all the same). I didn't have to give any new permissions or anything. I submitted the form and it worked!!! So my question is:
Is the any expiry date for triggers?
Does anybody have a clue for other possible reasons?
Does anybody out there had this problem already?
I hope there is an easy explanation.
Thank you*

Related

Google Apps Script problems running as different user

I am having problems with script execution from within my company's Google Workspace account.
I am the developer and I have no problem executing any of the scripts with my account; all my scripts run all the way to the end.
Now, there is this one script through which I present the user with a form in a sidebar for him/her to input some data, and then I do some stuff with that data. As mentioned, no problems for me. However, when I try to run it as another person from the company (which isn't just another editor but the superadmin account for the company's Google Workspace), after the initial script permission-granting dialogues are done and dusted, the script only runs halfway through and hangs. It actually gets the sidebar up, allows the user to input data and also to submit some data (I need to check if it submits all of the data). I know for a fact that some of the data does get submitted since one of the things the script does is fill up a particular cell with the data of one of the inputted fields, but it hangs there forever... How could that happen? I thought it might be a problem with the HTMLService, but as some of the inputted data does go through and gets added to the right cell..., I'm at a loss.
Has anyone encountered anything alike?
As it turned out, after I banged my head around for hours, it was a matter of dealing with protected cells.
Even though the script is set to execute as me, as soon as the script attempted to write into a protected cell whenever a different user executed it, and where I had set myself as the only user with write access, it failed.
Thanks go to #Kessy for having a look into it and suggesting a possible way to see the problem.

how to know if a Google Form has been submitted by the user in a web app

I would like to use Google Forms in my webapp to run quizzes.
The Google Form is created.
I use the pre-fill option to get a URL.
From my web app I create an iframe and pass the URL (different for each user) by passing the user-id to the form.
User now fills the form and submits.
The data is stored in a spreadsheet.
Earlier I publish the spreadsheet (thereby making it public).
I can now access the spreadsheet data and update my local database.
So currently, when the user submits (from within Google Form) there is no way my web app knows about it. (I have browsed the internet for solutions but did not find any).
Is there a way to get around this?
Currently, at some "stage" in the web app, I check if the user form data is available in the database. If not, I check the spreadsheet for that user data. If found, update the webapp database. So in that sense the webapp uses a pull-feature to check for updates.
Thanks
I see that you want to know when a new Form response has been uploaded. If my understanding of the question is correct, then you could use a simple .onEdit() trigger in the response Sheet. As an alternative, you could use a FormResponse.submit() installable trigger that fires at each response. Please keep in mind that triggers are limited to form uploads that don't fire from API requests and script executions, as detailed here. Please, don't hesitate to ask for further clarification.
UPDATE
Based on your last comment I get that your priority is to see the response Sheet updated in real time. If my understanding of the issue is correct, then you can show the responses Sheet directly in a webapp inside an iframe. Please, ask me any question if you have doubts about this approach.

onFormSubmit Trigger occurs twice randomly about every few weeks

Firstly, I want to say that this issue is different from all previous Form Submit Trigger errors with Google Apps script. This one triggers twice, while still having access to all form submit info of the previous form submission and triggers the program again.
Furthermore, the additional form submit trigger glitch does not add a row to the spreadsheet form responses, this is because the user isn't submitting the form twice, it's on Google for triggering it. This has happened randomly about 3 times in the past few months and it is extremely critical that my program only executes once for each job. After hours of research, I was unable to find a problem similar to mine. The problem also persisted even after adding the following line of code:
if(e.values && !e.values1){return;} //To fix error when onFormSubmit
triggers multiple times under one form submission //Doesn't work/do
anything 6/8/2020
Posting this for documentation purposes.
This behaviour was very recently reported on Issue Tracker, probably by the OP:
#158892709: onFormSubmit Trigger occurs twice randomly about every few weeks for one form submission
Anyone who might be experiencing this can click the star on the top left in order to subscribe to it and also to prioritize it.

Google script - Submit form response without having authorization to edit form

I have created a script for collaborators, to be used in google sheets.
When they trigger the script, it submits a form response, that then gets used to modify a "central" spread sheet.
But I am faced with a permission problem, and I haven't managed to find a convenient answer to it on the net.
The script uses FormApp.openById([...]).createResponse().[....].submit().
The problem comes from the fact both openById() and openByUrl() need the person who runs the script to be able to edit the form.
(As said on the Class FormApp help page : Returns the Form with the specified URL. Throws an exception if the URL is invalid or the user does not have permission to open the form.)
I have so far found 2 workarounds :
Give edit access for the form to my collaborators : it then shares them a form they shouldn't edit.
Change the link-sharing of the form to "on" : although no one but me actually knows the form Id, I don't really like the possibility of anyone discovering the link to be able to edit the form.
Neither of these workarounds completely satisfies me, and I'm sure there must be a way to submit a response via a script without being able to edit the form - just as people who send answers to google forms can't generally edit the questions ! Just I can't figure out how.
Any help on this problem will be very much appreciated !
Thank you,
Mike
Create a Web App using an account with owner or editor access to the form and set it to be run as the script owner. For a general guide see https://developers.google.com/apps-script/guides/web

google spreadsheet script trigger stopped working 4 days ago

I have a spreadsheet script using google spreadsheets that was firing on a daily trigger. Everything was running fine until a few days ago and suddenly it stopped working. The script sends me an email every day, around midnight. I was able to send a test email today but the operation that pulls data from my spreadsheet doesnt seem to be able to send the email. Ran it through the debugger and everything appears to be working fine. Does anyone know why something like this might happen?
First, you need to figure out whether or not your trigger is being invoked. If yes, click on notifications in the triggers window to set it up so that you receive an error email immediately. This way you'll see if your script gets any errors which might be useful in determining the next step.