newToScripts
newToScripts

Reputation: 69

event.source undefined in simulated onFormSubmit event

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

Upvotes: 2

Views: 428

Answers (2)

newToScripts
newToScripts

Reputation: 69

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!

Upvotes: 0

Cooper
Cooper

Reputation: 64062

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"}

Upvotes: 3

Related Questions