0
votes

How to get only the values from the submission that triggered onFormSubmit event in google appscript?

That is, when a google form response is submitted, is there a way to get only the row of values that corresponds to the form response that actually triggered the onFormSubmit in the first place (in a google sheet)?

So far, the only thing I could find was

let values = SpreadsheetApp.getActive().getSheets()[0].getDataRange().getValues();

which return all the sheet rows that then must be filtered somehow.

It seems odd that google sheets can detect an onFormSubmit event, but would have no method for actually getting the data from the submission that triggered the event.

1
For example, how about retrieving the values from the event object? Ref If you are required to retrieve from the Spreadsheet, how about using getLastRow? RefTanaike

1 Answers

2
votes

You can look https://developers.google.com/apps-script/guides/triggers/events

You can also do something like this:

function myOnFormSubmit(e) {
  console.log(JSON.stringify(e));
}

And sometimes you get a better picture of what is there.

Here's an example:

{"authMode":"FULL","namedValues":{"1":[""],"2":[""],"Timestamp":["6/29/2020 18:55:10"],"one":["Option 1"]},"range":{"columnEnd":2,"columnStart":1,"rowEnd":14,"rowStart":14},"source":{},"triggerUid":"","values":["6/29/2020 18:55:10","Option 1","",""]}

So e.range.rowStart is the row that was just edited in the Response Sheet and e.range.getSheet().getName() is the name of the Response Sheet