Google Forms
  • 22 Jun 2023
  • 1 Minute to read
  • Dark
    Light

Google Forms

  • Dark
    Light

Article Summary

Forms are a common way to collect information from internal and external users for processes such as IT requests, employee onboarding, and so on.

Google Apps Script enables you to create scripts that automate tasks for Google applications, such as Forms, Drive, Docs, Calendar, and so on.

This article explains how to create a script that automatically sends a JSON of a Google Form (including questions and answers) to an endpoint.

In Torq, you'll create a webhook integration that generates a unique Torq endpoint, which you'll add to the Apps Script.

These instructions assume that you already created a Google Form.

1. Create a Google Form integration in Torq

  1. Go to the Integrations page, search for the Google Form card, and click Add.
  2. Enter a meaningful name for the integration, such as google-form-trigger, and click Add.
  3. Copy the webhook URL.

2. Create a test workflow

  1. Go to the Workflows page and click Create Workflow.
  2. Type a meaningful name for the workflow, such as Google Form Trigger.
  3. Select the Integrations trigger and click Pick Integration.
  4. Search for Google Forms, click the card, and select the integration you created earlier.
  5. Save the workflow.

3. Configure the Google Form

To configure the form, you'll create the form, add a custom script, and define the form trigger.

  • Open the Google Form and click the vertical dots and select <> Script editor.
  • Copy the following script.
var POST_URL = "enter your webhook URL";
    function onSubmit(e) {
        var form = FormApp.getActiveForm();
        var allResponses = form.getResponses();
        var latestResponse = allResponses[allResponses.length - 1];
        var response = latestResponse.getItemResponses();
        var payload = {};
        for (var i = 0; i < response.length; i++) {
            var question = response[i].getItem().getTitle();
            var answer = response[i].getResponse();
            payload[question] = answer;
        }

        var options = {
            "method": "post",
            "contentType": "application/json",
            "payload": JSON.stringify(payload)
        };
    UrlFetchApp.fetch(POST_URL, options);
    };
  • Paste the script in the editor and replace "enter your webhook URL" with the webhook you created for the Google Forms integration.
  • While on the script editor, select Triggers from the left pane, and then click Add Trigger.googlesheets triggers
  • In the Create Trigger dialog, set the Select event type property to On form submit, and leave all other parameters to their defaults.trigger google forms
  • Click Save and then Approve.



Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.