Skip to content
Advertisement

Google Apps Script successfully triggers On Form Submit, but function will not execute

I’m trying to copy a row from the linked form responses sheet “main” to another sheet “sub” if a value in the form response matches a particular criteria, Column 4 = “Subset”

I have onFormSubmit set up as a trigger with Deployment – Head, Source – Spreadsheet, Event – On form submit. When I submit the form, the trigger for onFormSubmit logs the execution as Completed but the row does not copy to the “sub” sheet.

The getLast function allows me to move the row to the next available position in the “sub” sheet starting in the second column because I have checkboxes in the first column all the way down the sheet.

The code works as is when using the onEdit function and manually entering “Subset” into column 4. I can’t seem to figure out why nothing happens with onFormSubmit even though the trigger is successfully executed. Please help!

JavaScript

Advertisement

Answer

I thought that from your question, when your script is run by OnSubmit trigger, the if statement of if(s.getName() == "main" && r.getColumn() == 4 && r.getValue() == "Subset") {} might be always false, because in this case, the range is not the column “D”. By this, your script doesn’t work. I thought that this might be the reason of your issue.

When the OnSubmit trigger is fired, in order to run the script in the if statement, how about the following modification?

Modified script:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement