Google Form onFormSubmit not triggering - google-apps-script

I have an issue with a google form I am working on. I set up the trigger as seen below.
When the form is submitted an alert box should pop up with information taken from a google sheet.(The form is linked to the sheet)
When I run the code from the script editor it shows the popup in the form, but the trigger never trips when I submit a response to the form.
I have tried:
deleting trigger
creating a new version of the script
adding trigger back
change trigger to TimeDriven and still no trigger
change the script to standalone with the same trigger
Not sure what the issue is since I can execute the code manually.

As Sandy Good states:
A dialog box can't be shown in "View" mode of a Google Form. When you are running the code from the script editor, the pop-up that you are seeing is probably in the "Edit" mode of the Google Form. "On Form Submit" doesn't run from Edit mode. If you are trying to get something to display to the user after they submit the Form, then your only option is the confirmation message: FormApp.getActiveForm().setConfirmationMessage(message)
Using .setConfimrationMessage(message) works for what I want to do. (Give a list of sheet cells when the response of the form is submitted)

Related

Google Sheets Submit button script won't work for users

I have a submit button script that I'm using (source: https://www.youtube.com/watch?v=v2X-fArILPA) and it works great when I am signed in, BUT it won't activate when users press the submit button. When I test the form in an incognito browser to simulate a user, I get a red box error that reads "Script Submit experienced an error Details
Dismiss" when I click on the submit button. When I click on "Details" it repeats the message "Script Submit experienced an error" in a new pop up window.
Sharing settings are set to anyone with a link is editor. Certain cells are protected, but not the input cells.
Is there a setting or script that I need to write to allow this script to run for users of the spreadsheet? Thank you in advance!
I've tried using triggers, but they don't allow the user to more than one cell value in before triggering the submit script. I also tried a different script to see if it was perhaps the script itself. Both are doing the same thing.

Programmatically stop the submittal of a google form based on selected values using Apps Script

I have a google form that has a few checkboxes with values assigned to them something like...
Select your options:
Option 1 - $100
Option 2 - $150
Option 3 - $75
When the google form is submitted (or a button is clicked) I would like to check and make sure the values selected add up to $150 or less, but not over. If they are over I would like to display a message stating "this cannot be done" or something like that.
Is this possible with App Script?
Thanks,
Keith
I was searching around about what you are trying to do and it seems that once the form is submitted you won't be able to trigger any message as the user will be sent to the confirmation screen, you could only change the confirmation message using the .setConfirmationMessage(message) method however this would not be applied immediately and it would be displayed next time someone submits the form again.
Pretty much we can't conditionally set a message based on the answers placed by the user not even by placing a trigger on form submit.

Google script embedded in google sheet adding a menu item

What I tried is adding some functionality to my google sheet (creating events and pushing them to the google calendar). Everything works, but when I close the script editor my menu disappears.
I created the menu items like so:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Sync to Calendar')
.addItem('Create Events Now', 'CreateEvent')
.addItem('Delete All Events in Calendar', 'DeleteAllEvents')
.addToUi();
}
That works just fine, but I would like to close the script and also when I share the spreadsheet, the member shall be presented with the menu to click and execute the functions. Anyone has a solution how to make that permanent? (without publishing the script which would be an overkill in my opinion)
In some cases OnOpen doesn't run automatically unless the editor has authorized the script. In this case, you need to give editors a way to trigger the script, so they may authorize it, before onOpen will run automatically. You can either give them instructions to do this manually through the script editor, or you can insert a "button" into the sheet.
To do this "button" - insert an drawing into the sheet (the "button"), bind the drawing to your script, and have first time users click the drawing.
In your spreadsheet, click "Insert" -> "Drawing"
Draw a "button" image with useful text for end users ("Show custom menu" or "No menu? Click here!", etc.)
Place the drawing on your spreadsheet in a visible/convenient location.
Click the "three dots" on the drawing and select "Assign Script"
Enter the name of the function (eg OnOpen)
If a user opens the sheet and doesn't see your menu, they can click this "button" to activate the script. They'll be prompted to authorise the script as needed, then the menu will show from that point forward. They should only need to click the button the very first time they open the sheet, unless the scopes change or they manually remove authorization in account settings.
onOpen is a reserved word for a function to be called automatically when a Google Sheets spreadsheet is opened by the spreadsheet owner or editors, it will not run for viewers.
You should check that in the project there isn't any other function named onOpen otherwise another function declaration could be executed instead of the one that you expect.
Reference
https://developers.google.com/apps-scripts/guides/triggers
The suggested answer from Cameron Roberts works as a workaround.
Although in my case the problem was that the script trigger for onOpen was missing. I had to edit the script trigger within the script I wrote. In the script editor go to "Edit" -> "Current projects triggers" and add a trigger for the onOpen function with an event "on open". Apparently that was missing in my case, after that edit, it worked like a charm.

Displaying a Google form on sheets

I am creating a form for users to input information on a Google spreadsheet. They will access the spreadsheet and then click on an image that is linked to a script. When the image is clicked, I want a form to appear. Then I want the input from the form to be accessible in the script.
I am able to create a form but the form does not appear on the sheet. Here is the code thus far for the GS script
function startForm() {
var form = FormApp.create('myForm');
var item = form.addCheckboxItem();
item.setTitle('What would you like to do?');
item.setChoices([
item.createChoice('Budget Inquiry'),
item.createChoice('Add Purchase')
]);
var choices = item.getChoices();
// then I can respond to the user's choice
}
I would like this simple form to just appear on the google sheet. Any input would be appreciated.
Instead of creating you own form with script, just go to the insert menu of your spreadsheet and select form. Enter you question and your two choices. Close the form. You will see a form response sheet created in your spreadsheet. Also, a menu item Form will appear on your menu. Then go to the script editor and from the menu select Resources. Select Current Project Triggers and set a new trigger for onFormSubmit. You can then enter a function onFormSubmit to do whatever you want done when the form is submitted getting data from the form response sheet. There is plenty of documentation you can Google.
The way in Google Sheets to display external content other than images and Google Drawings is by creating a dialog or sidebar with the related content embeded.
There is a similar question that includes an answer that shows how to do this:
Single Google Form for multiple Sheets

Google Forms, sidebar for live form

I would like to create a sidebar to a live google form, ideally in order to pick from a (google) map coordinates to be entered in the form.
From the documentation and from my trials I can create a sidebar to the form editor/designer (https://docs.google.com/forms/d/ID/edit), not the live form itself (https://docs.google.com/forms/d/ID/viewform). Forms are different in regard to the Doc and Sheet Apps, that there exist these two views.
For example:
function onOpen() {
var ui = HtmlService.createHtmlOutputFromFile('Sidebar')
.setTitle('Maps');
FormApp.getUi().showSidebar(ui);
}
First problem is that the trigger for onOpen() fires when opening the form designer, not when the end user will open the form (/viewform URL) to fill it out.
Then FormApp.getUI().showSidebar(ui); gets the UI of the forms designer and opens up a sidebar there and not in the Form the end user has to fill out.
Documentation seems to confirm this.
So, is it possible to get access to the live form, including any associated triggers?
So, is it possible to get access to the live form, including any
associated triggers?
No
However, you could embed your form in a page that also hosts the map in a separate frame, enabling users to browse the map, click to see coordinates, and then copy them to the form. There would be no interaction between the google-hosted form and the map.