Google Forms - is there an onSubmit function where it triggers only if it is approved? - google-cloud-functions

My workflow is like this:
2. The client completes the form
3. it sends to the approver and the person approves the form
4. When approved, i want it to trigger a function
is there something similar to OnSubmit function?
EDIT: i just found out that add-on is not for really for free. So i cannot use it. If there are any alternative solutions.
Thanks

Related

My OnFormSubmit trigger needs to complete before add-on's OnFormSubmit trigger fires

I'm using the Form Publisher add-on with Google Forms in order to turn each Forms response into a Google Doc. It's a great add-on.
I've written my own OnFormSubmit trigger (Head deployment; part of an app-script library) that renames the file(s) the form user may have uploaded as part of their form response. (The filenames are only available from the Drive.App file object, not from the form response itself.)
Based on the upload filenames that Form Publisher puts into the Google doc it generates, I can tell that sometimes the doc is being generated BEFORE my OnFormSubmit renames the files, and sometimes it is being generated AFTER my OnFormSubmit fires.
So my question is this: Given that I have no real knowledge of how Form Publisher works (though I would think OnFormSubmit would be at the heart of it), is there any way that I can assure that my OnFormSubmit will fire and finish before Form Publisher begins to generate the Google Doc?
Thanks, iansedano! I've continued to test and research, and everything I've seen points to your comment being correct.
I'm afraid that if you have two triggers that fire from the same event there is no way to ensure one starts/finishes before the other. They go off to the server asynchronously so the order will never be dependable. The way you normally deal with this is to make them part of the same trigger, but since you are mixing and matching your own script with closed source add-on script, that is not possible. If you wanted your one to fire after then you could just use a delay, but to make it fire before, you will probably be best off writing your own script.
For the record, there appears to be one small glimmer of hope here. I read that post's answer as saying that an add-on could use #customfunction to expose a function that my OnFormSubmit trigger could call; that custom function could then, for example, put the add-on to sleep for a bit (or even better: sleep until I call a second custom function to signal that I'm done) in order for my OnFormSubmit trigger to go first.
But other than that possibility, I've come up with nothing.

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.

Force auto-submit a Google Form using app-script?

I am using a code which closes the FORM at specified time. So what happened is some students are failing to submit it before the time limit and their responses are not being recorded.
Is there any way to force auto-submit a google form at specified end-time for all the users who are writing the quiz lets say!
Any ideas are welcome.
You can check this documentation about Installable Triggers which let Apps Script run a function automatically when a certain event occurs. It is similar to simple triggers for Google Apps like onOpen(), but they can respond to additional events, and they behave differently.
There are several installable triggers for Google Apps and you can use an installable form-submit trigger that runs when a user responds to a form.
Be noted that there are two versions of the form-submit trigger, one for Google Forms itself and one for Sheets if the form submits to a spreadsheet.

How to connect Apps Script to a Google Form submit button?

I have a simple Google-form for registration users on my service and they need to enter time when they will come. Its a problem when they can enter the same time that another user had placed and I need to check it when user push the submit button.
How can I do it with Apps Script? I have found few examples but still dont understand how to connect my script with submitting.
It's not possible to use Apps script to check data entered into a form pre-submission (Even with triggers, which are all dependent on the data being submitted). In order to do something similar using Apps script, you would need to use the HTML service to write a custom form with a function that allows you to check what data is submitted, and return an error message/refuse to accept the date if it clashes with a pre-existing date.
You are essentially trying to do something similar as the choice Eliminator Forms add-on.
Search the documentation for on form submit trigger. And it will give you an example.
But the catch 22 of it, is that your script runs after the form is submitted, so there is no way to stop the submission if it fails your check.

How to call a function in a Google Spreadsheet from code in a Google Form?

I have a Google Sheet which has amongst other things, a function to create an invoice based on a specific job's data, createInvoice(jobNumber).
I would like to have a form in which I enter the Job Number and on Submit have it run createInvoice(jobNumber).
So the question is: What kind of coding is required to run createInvoice(jobNumber) from the form?
Thanks heaps in advance for any help with this.
Your options for running functions when the form is submitted is using an installable trigger. Specifically, a form submission trigger, either on the form itself, or on the spreadsheet the data is written to.