Home > Web Front-end > JS Tutorial > Automation for Google Forms

Automation for Google Forms

WBOY
Release: 2024-07-27 14:07:52
Original
1102 people have browsed it

Automação para formulários Google

PT-BR

I was asked to create a smart form, where it would update a specific item according to what the user entered. As a kind of ID.

Through AppsScript, I created the following code below to accomplish this:

function updateForms() {
    const id = "Enter your SpreadSheet ID here!";
    const sheetName = "Enter the Sheet's name of items want to be auto uploads!";

    const ss = SpreadsheetApp.openById(id);
    const sheet = ss.getSheetByName(sheetName);
    const range = sheet.getDataRange().getValues(); // i recommend you do a sheet only to set data'll be upload

    const choiceValues = [...new Set(range.map(row => row[0]).filter(value => value))];

    const form = FormApp.openById("Enter your Forms ID here!");
    const items = form.getItems();

    for (var i in items) {
      if (items[i].getTitle() == "Set here the question name of Forms!") {
        items[i].asListItem().setChoiceValues(choiceValues);
        return;
      }
    }
    Logger.log("Nothing found...");
  }
Copy after login
Copy after login

The code was to update the data that would feed a weekly report.

Find more information in the repository.


EN-US

I was asked to create a smart form that would update a specific item based on what the user entered. Like a sort of ID.

Using AppsScript, I created the following code to do this:

function updateForms() {
    const id = "Enter your SpreadSheet ID here!";
    const sheetName = "Enter the Sheet's name of items want to be auto uploads!";

    const ss = SpreadsheetApp.openById(id);
    const sheet = ss.getSheetByName(sheetName);
    const range = sheet.getDataRange().getValues(); // i recommend you do a sheet only to set data'll be upload

    const choiceValues = [...new Set(range.map(row => row[0]).filter(value => value))];

    const form = FormApp.openById("Enter your Forms ID here!");
    const items = form.getItems();

    for (var i in items) {
      if (items[i].getTitle() == "Set here the question name of Forms!") {
        items[i].asListItem().setChoiceValues(choiceValues);
        return;
      }
    }
    Logger.log("Nothing found...");
  }
Copy after login
Copy after login

The code was to update the data that would feed a weekly report.

Find more information in the repository.

The above is the detailed content of Automation for Google Forms. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template