Access to user data entered when sending to Google

I have a google form that has the following two fields:

  • Email Address: - Text Box
  • Tool: - switch
    • Tool 1
    • Tool 2
    • Tool 3

The user enters his email address and selects the tool and presses the "Submit" button. I would like the following message to appear:

Thanks for answering. An email has been sent to you at the indicated email address to download the selected tool.

I have the following code snippet in a script editor

    function emailFormSubmission() {
        var form = FormApp.getActiveForm();//the current form
        var dest_id = form.getDestinationId(); //the destination spreadsheet where form responses are stored
        var ss = SpreadsheetApp.openById(dest_id);//open that spreadsheet
        var theFormSheet = ss.getSheets()[0]; //read the first sheet in that spreadsheet
        var row = theFormSheet.getLastRow(); //get the last row
        var emailid = theFormSheet.getRange(row,2,1,1).getValue();//get column 2 corresponding to the email id. column 1 is timestamp. so, skip that.
        var tool = theFormSheet.getRange(row,3,1,1).getValue();//get column 3 corresponding to the selected tool.
        form.setConfirmationMessage('Thanks for responding. An email has been sent to you '+ emailid + ' to download' + tool);
    }

I also installed triggersto run → emailFormSubmission, → Events Read from Form, onFormSubmit.

: , ( "A" ) "". . ( "B" ) "", . ( "C" ) "", B. , "getlastrow()", FormSubmission.

? ?

UPDATE

@wchiquito, , .

function emailFormSubmission(e) {
    var form = FormApp.getActiveForm();
    //Check this link on how to access form response:
    //https://developers.google.com/apps-script/understanding_events?hl=en

    var responses = e.response;//e is of type formresponse.
    var emailid = responses.getItemResponses()[0].getResponse();
    var tool = responses.getItemResponses()[1].getResponse();
    Logger.log(emailid);
    Logger.log(tool);
    form.setConfirmationMessage('Thanks for responding. An email has been sent to  '+ emailid + '   with instructions to download ' + tool +'. If you do not find our email in your inbox, please check your spam folder');  
    Logger.log(form.getConfirmationMessage());
}
+3
3

, On form submit ( ) , :

  • namedValues ​​

- :

function emailFormSubmission(e) {
    ...
    var row = e.range.getRow();
    ...
}

, e:

function emailFormSubmission(e) {
    ...
    Logger.log(e);
    ...
}

UPDATE

-, , Spreadsheet form submit event, Form submit event.

, a Form submit event :

FormResponse.

, : On submit form (Form submit event), - :

function emailFormSubmission(e) {
  var itemResponses = e.response.getItemResponses();
  for (var i = 0, len = itemResponses.length; i < len; ++i) {
    Logger.log('Response #%s to the question "%s" was "%s"',
               (i + 1).toString(),
               itemResponses[i].getItem().getTitle(),
               itemResponses[i].getResponse());
  }
}

, , , , , , .

+6

- :

var emailid = theFormSheet.getRange(row,2,1,1).getValue();//get column 2 corresponding to the email id. column 1 is timestamp. so, skip that.
var tool = theFormSheet.getRange(row,3,1,1).getValue();//get column 3 corresponding to the selected tool.

getLastRow() , . , , , +1, . , , .

, :

var emailid = theFormSheet.getRange(row+1,2,1,1).getValue();
var tool = theFormSheet.getRange(row+1,3,1,1).getValue();

, , Google. , [] [][] , , getValues(). getRange() a sheet 1 ( , ). , " " - . :)

+1

Short answer: you want you to not be able to be executed using Google forms.

Explanation: form.setConfirmationMessage () sets a confirmation message for a form stored on the server, and not for the current active form. The same applies, for example, to form.setTitle (). The active form will not be changed. Different behavior could be expected for the confirmation message, but alas, this is not so.

0
source

Source: https://habr.com/ru/post/1599785/


All Articles