0

I am new in appscript and now i want to store the responses filled in the form in a array and then use this array to store the data in a custom format in a spreadsheet, the problem is that i am trying to store and send the response with a manual trigger onFormSubmit, when i submit the form, some information about the sheet i want to modify is logged in console but the data itself can't be retrieved, below is what i am trying, first approach is to get the active form and the second is to catch the response from event, but neither of them are working. how can i accomplish it?

var SPREADSHEET_ID = "SPREADSHEET ID",
    SHEET_NAME = "SHEET NAME";

function onFormSubmit(e) {
    var sheet = SpreadsheetApp.openById(SPREADSHEET_ID),
        form = FormApp.getActiveForm();
    
    var formResponse = e.response;
TTT2
  • 549
  • 2
  • 13
  • It sounds to me that you have create a form using a google sheet and there is no onFormSubmit trigger for that kind of form. As a matter of fact those really are not forms at all. OnFormSubmit triggers are only for Google Forms. – Cooper May 18 '22 at 15:21
  • no, the sheet is somthing apart, i want to catch the response from the form that is activated with a triged when form is submited, then open the existing sheet and store the response in a custom format – TTT2 May 18 '22 at 15:28
  • What form are you talking about? – Cooper May 18 '22 at 15:32
  • Is it a Google Form? – Cooper May 18 '22 at 15:33
  • 1
    If it's a Google Form then there are two onFormSubmit triggers one is for the Form and one is for the linked spreadsheet. – Cooper May 18 '22 at 15:35
  • this is a apps script from a google form, sorry for not being so specific in the question, english is not my mother language, the sheet is not binded with the form, the response are not stored in a sheet i dont want to store them. just want to catch the response every time is submited and fill in a spreadsheet the responses – TTT2 May 18 '22 at 15:37
  • 3
    Well in the end it seems that you wish to store the responses in a spreadsheet so I would recommend linking the form to that spreadsheet and using the onFormSubmit trigger for that spreadsheet and all the values are available in the event object in either namedValues or values. If you don't link it to a spreadsheet then the onFormSubmit trigger will only fire for the Form and an entirely different response is involved. – Cooper May 18 '22 at 15:41
  • 1
    TTT2 : As it was mentioned by Cooper the event object of the form submit trigger from a spreadsheet includes a property having an array of the form responses. In terms of execution time this is more efficient than trying to build an array from a response object. If you need further help, please [edit] the question to add the appropriate details. – Rubén May 18 '22 at 15:45
  • how can i do it? i dont have the sheet linked i just open it by ID, do i have to go to answers tab and set the sheet i want? but when i do this the responses are stored in a new sheet in standar format, i.e a signle row with columns of answers – TTT2 May 18 '22 at 15:46
  • 1
    [here](https://stackoverflow.com/questions/57197511/google-app-script-get-content-of-google-form-response-when-submitting) it is a solution following your advices , thanks – TTT2 May 18 '22 at 15:51

1 Answers1

0

I'm writing this answer as a community wiki, since the solution was provided by OP in the comments section. This, to provide a proper response to this question.

Since OP does not (as mentioned in the comments) have a Spreadsheet linked to the form in use, does not want to store responses in any Spreadsheet but only catch the responses as they are submitted, solution was provided in the comments by OP where basically:

An onFormSubmit trigger is set up with:

  • getResponse() as a function in the form of:

function getResponse(e) { var response = e.values; }

  • From Spreadsheet as the Event Source

  • On form submit as the Event Type

In this scenario, the event objects are used to get the values submitted in the form response. Resulting in the desired outcome below:

[25/07/2019 10:02:36, Option 1, Answer 2, Option 3]

Yancy Godoy
  • 582
  • 2
  • 13