skip to Main Content

I have a form submit trigger configured from apps script like this:
enter image description here

The onSubmit function is this:

function onSubmit(e) {
  console.log("Form submitted", JSON.stringify(e.namedValues));
  console.log("Form submitted", JSON.stringify(e));

}

But whenever I submit the form, the trigger does get fired and function runs. But e.namedValues is undefined.

enter image description here

What could be wrong? (I have linked a spreadsheet to the form which also did not change the outcome).

2

Answers


  1. The source should be from Spreadsheet.

    There is no namedValues on the trigger for the form.

    Login or Signup to reply.
  2. Google Forms: Retrieve Responses Automatically

    This sample script allows you to retrieve responses submitted to your Google Form automatically in the Executions tab of Google Apps Script.

    Note: This may be similar to @Cooper‘s approach in his last comment.

    const onSubmit = (e) => {
      var response = e.response;
      var itemResponses = response.getItemResponses();
      var formResponse = {};
    
      itemResponses.forEach(itemResponses => {
        var itemTitle = itemResponses.getItem().getTitle();
        var value = itemResponses.getResponse();
        formResponse[itemTitle] = value;
      });
      console.log("Answer submitted: " + JSON.stringify(formResponse));
    }
    

    The sample form looks like this:

    image

    OUTPUT

    image

    REFERENCE

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search