Can onFormSubmit() trigger be triggered by something else other than a human submitting a Google form? - google-apps-script

I have a Google form, it is set up to send emails on completion of the form. I followed http://www.labnol.org/internet/auto-confirmation-emails/28386/ pretty much exactly, just changing the text mainly. And it does indeed send emails on a submit, hooray!
The form itself has required questioned so a human shouldn't be able to submit the form without filling at least those questions in.
However, over the weekend (on Sunday 11th), three emails were sent with blank responses, even to the required questions!
So I think there are three likely explanations:
The required questions didn't work / structure of the form
momentarily errored and allowed three blank responses from a human.
Some sort of robot / crawling script somehow triggered a null submit
The form was completed by a human and the data was not recorded, nor included in the email.
Do any / all of those explanations make sense / seem plausible?
And if 3 is the answer, do you know if it was a transitory, maybe documented, error that happened on Sunday?

I do not see why a bot could not submit a google form. The onSubmit trigger is just as it sounds. As soon as the form is submitted the google script runs so regardless of what sends the information as long as it was submitted to the form the script will run.
This scrip does a check against blank data for the text body of the e-mail but nothing else.
I have tested this and can confirm that even if your google form has a question set as required, if it is a text or paragraph entry then all you have to do is enter space and it will consider that valid data. All form submissions should be stored on a google spreadsheet so I would recommend checking the spreadsheet responses to see if the cell is actually blank or if it contains data like ' '.
Personally I always use specific ranges when doing an auto response or if I need to work with data from a form submission. Generally data should always be in the same place on the spreadsheet.
Your script runs whenever a form is submited. So if a bot can bypass the check if question is empty and still submit it then your script will run anyway.

Related

Button in email to change cell value in google sheets

I am designing a ticketing system that runs through google forms and sheets. I want the agents to never have to interact with the actual sheet. I want to have a link/button in the email ticket where the agent can mark as resolved and the value in a cell in the sheet gets changed automatically.
Is this feasible?
It is possible and there are a couple ways to do it. I would suggest the below slightly different method than what your question asks (what if they accidentally click it!?).
Since you're already using google forms, I would send your people a link to another form that confirms a ticket should be closed. You code the link to pre-populate the ticket number to ensure that there's no human error in making sure they entered the proper ticket number.
See example to a form here with a link that will populate the form with a number from the link (I used your question #)
Once the user clicks submit, you can use that event to have your app script go modify your spreadsheet accordingly.

How can I trigger a Sheets script from a Google Form Submission?

I wrote a script for a Google Sheet that emails a user some specific info relevant to them alone. It works fine with the onOpen trigger, but I don't want them to have to open the sheet each time.
It would be easier to submit a form request and then receive the email but I'm not sure how to do that. I'm sure this is very basic so apologies for that, I'm new to this.
Basically I would like to form to ask if they want to receive an email with the info, and if they say yes, it triggers the script.
There are two ways to do this. The first is to:
Link the form responses to the spreadsheet
Add the installable trigger on form submit to the spreadsheet on the function you want to run.
Get the necessary information from the event object to see who submitted the form.
The second way is to:
Place a script on form.
Put an onFormSubmit() trigger on the form
Have the form open the spreadsheet - SpreadsheetApp.openById()
Copy paste the spreadsheet code into the form, making adjustments, so it will run (will mostly be how to get the user data)
If you would like this to only occur if the respondent asks, you can place a yes/no question on the form and check the answer. You can also have a questionless form that only collects emails, if you just want them to submit it to trigger an email.
there might be useful to do a template with a form with two buttons, 'Yes' or 'No'. If they hit 'Yes' you can hit an API in your platform to run script.
Maybe you can use a redis or some database to save the preferences of this user.
Hope it helps.

Google Script MailApp - Setting Timer

Are there any possibilities that I can control how long it takes after a form has been submitted before it will send an email out?
Currently, my code is working with a onFormSubmit function. So whenever a form is submitted and I have google script that has IF statements which checks for a range of values.
I want to improve the code but I can't think of any for the past few days. My plan is to send an email lets say, 10 minutes after the form is submitted. Let say, the form submitted has typos in it and one of the values isn't supposed to trigger an email send but instead it does due to the typo.
So now, I want to edit that value to the correct value which is within the accepted range. If this is being edited within that 10 minutes and is being checked again that it is actually within the range, then the email will not be sent. Is there any way this can be done? I have read up a bit about the function onEdit but it does not really cater for my requirements.
A solution I can think of:
onFormSubmit run a Clock trigger builder that will, lets say after the chosen amount of time run a function. Within this function you can verify if an edit to the form has taken place (retrieve the form submit data from the destination spreadsheet) and send an email if required.

Multiple OnFormSubmit trigger to specific spreadsheet

So, we have this task where we have a Google Form where a user submits data as a sign up for a mentoring service that gets passed on to a Spreadsheet and the user gets an e-mail as a sort of like confirmation that the sign-up did indeed happen. During this, the mentor that the user specified also gets an e-mail with some of the information that the user has sent, and a link that redirects them to a pre-filled Google Form that contains some of the information that the user submitted, and a drop-down question that basically serves as an attendance check.
Now, all of that mentioned already works. The problem is, the way it is set-up is that there are 2 Google Forms that direct to the same spreadsheet, just in different tabs. If I try to use OnFormSubmit as a trigger for the functions that allows for the emails to be sent, what happens is both OnFormSubmit triggers occur at the same time. I've seen multiple solutions to this problem here but none of them seem to work for me. Is there a way to manually script the OnFormSubmit function to let it work only when a specific form is passed?

Record Time taken to complete a google form

I am trying to record the total time taken to complete and submit a Google form.
My logic is simple that the following code would record and put the timestamp as a multiple choice option.
Then upon submitting the form, we get a time stamp anyway but along with that, we would get the initially recorded timestamp as an answer to that question.
This is my cute little code:
function initial() {
var form = FormApp.getActiveForm();
form.getItemById(1589920082).asMultipleChoiceItem().setChoiceValues([new Date()]);
}
I have set the trigger as OnOpen but surprisingly, it does not renew the timestamp every time I open the form. Theoretically, it should record the time when the form was open but I think I am missing something here.
On the other hand, if I change the trigger to OnSubmit, it starts recording fresh timestamps every time I submit the form. But I don't want that as we get submission timestamps anyway. What I am trying to record is the time the form was open.
I know this question was asked a year ago, but here is a workaround I just came up with.
Have 2 forms! The first form can be a disclaimer, instructions, etc. The second form is the original form you intended for the users to fill out. Turn on email collection for both, so you can know which user submitted the test.
Get the sharing link and in the settings of the first form add the link in the confirmation message:
Then link both forms into a spreadsheet and you will see the time stamp of each submissions. From there you can easily do a calculation to determine the duration.
Unfortunately you cannot have any code executed when user opens form for filling in, as onOpen trigger is not supposed to be run in this case:
https://developers.google.com/apps-script/guides/triggers/#onopen
The onOpen() trigger runs automatically when a user opens a spreadsheet, document, or form that he or she has permission to edit. (The trigger does not run when responding to a form, only when opening the form to edit it.)
There is an open feature request in Google Issue Tracker to introduce some kind of onOpen trigger when form opened for response, you can "star" it to make it more possible to appear: https://issuetracker.google.com/issues/63985842