2

I have a google form that is linked to a google sheet.

When I submit the actual form, onFormSubmit is triggered and my logs show " e.source Spreadsheet"

I was also using the simulated onFormSubmit code from this link (How can I test a trigger function in GAS?) to debug and everything was working fine.

Suddenly I am getting an error "e.source undefined" but e.values is working fine when I use the simulated onFormSubmit code.

What could have caused this sudden error, particularly since it seemed to have been working fine before for exactly the same scenario?

TIA

newToScripts
  • 69
  • 1
  • 2
  • 10
  • Your probably using he [onFormSubmit](https://developers.google.com/apps-script/guides/triggers/events#form-submit) for spreadsheets instead of the [onFormSubmit](https://developers.google.com/apps-script/guides/triggers/events#form-submit_1) for forms. – Cooper Oct 10 '19 at 17:02
  • Thanks much, how do I know which of the two is being fired? Because even when I submit the actual form and the onFormSubmit(e) is triggered, my logs show "e.source is Spreadsheet" And the simulated event test_onFormSubmit() was working fine before, so I am not sure what could have caused it to suddenly give the error "e.source undefined" – newToScripts Oct 10 '19 at 17:25
  • Well actually as you'll note in my answer they both have a source parameter that I found by using `Logger.log(JSON.stringify(e));` The question isn't which one is firing but which one your looking at. If you're in the spreadsheet and you have installed the trigger for that project then the spreadsheet is responding to the Form Submission. However, you could also set up a trigger for the Form using script editor of the Form. So the real question is where did you create the trigger. – Cooper Oct 10 '19 at 17:47
  • Is your code in the spreadsheet script editor? – Cooper Oct 10 '19 at 17:57
  • I would suggest, if you're not sure which trigger is set up, to use an [Installable trigger](https://developers.google.com/apps-script/guides/triggers/installable#managing_triggers_manually), it will be specific on which what kind of trigger it is, where does it originate and what it runs. – AMolina Oct 11 '19 at 07:09

2 Answers2

3

onFormSubmit for spreadsheet doesn't a source parameter.

onFormSubmit for forms does have source parameter

enter image description here

onFormSubmit event object for Spreadsheet Above:

onFormSubmit event object for Forms Below:

enter image description here

Upon further investigation, there appears to be a source parameter in both objects according to Logger.log(JSON.stringify(e));

The is the Log for the Spreadsheet:

[19-10-10 10:34:03:681 PDT] {"authMode":{},"values":["10/10/2019 11:34:03","url"],"namedValues":{"Timestamp":["10/10/2019 11:34:03"],"UploadTesting":["url"]},"range":{"columnStart":1,"rowStart":27,"rowEnd":27,"columnEnd":2},"source":{},"triggerUid":"id"}

This is the log for the form:

[19-10-10 11:34:04:636 MDT] {"authMode":{},"response":{},"source":{},"triggerUid":"id"}

Community
  • 1
  • 1
Cooper
  • 59,616
  • 6
  • 23
  • 54
  • Thanks much, but I am still not very clear about which is fired when. Because even when I submit the actual form and the onFormSubmit(e) is triggered, my logs show "e.source is Spreadsheet" And the simulated event test_onFormSubmit() was working fine before, so I am not sure what could have caused it to suddenly give the error "e.source undefined" – newToScripts Oct 10 '19 at 17:22
  • Let me investigate by running the logger on both. – Cooper Oct 10 '19 at 17:27
0

Thank you!

The above answers helped me find out my mistake.

I had added a line of code which referenced "e.source".

I was getting an error when executing this code from the simulated onformsubmit which was generated from spreadsheet data. The eventObject being called in this case does not have a "source" parameter (as pointed out in answers above) and hence the error.

When I ran code by submitting an actual form, it was working fine since the eventObject in this case does have a source parameter.

Thank you once again!

newToScripts
  • 69
  • 1
  • 2
  • 10