DEV Community

Matheus Coelho
Matheus Coelho

Posted on

Automação para formulários Google

PT-BR

Me pediram para criar um formulário inteligente, onde ele atualizasse um item em específico de acordo com o que o usuário inserisse. Como uma espécie de ID.

Através do AppsScript, criei o seguinte código abaixo para realizar isso:

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...");
  }
Enter fullscreen mode Exit fullscreen mode

O código era para atualizar os dados que alimentariam um relatório semanal.

Encontre mais informações no repositório.


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...");
  }
Enter fullscreen mode Exit fullscreen mode

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

Find more information in the repository.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up