Google Apps Script - Require One Response per Row for Grid Item

I am creating some student surveys with Google Forms using Google Apps Script. The question type I'm using is a grid item. Each row is a question about the teacher and each column is a rating (strongly disagree, disagree, etc...).

When creating a form using the normal Forms interface there is an option to require a response for each row within a grid item. I've searched through all the documentation and it appears there is no way to set this using GAS. Am I missing something or is there any workaround?

I can go in and manually set this after all forms have been created but there are a lot of classes and teachers so it will be quite time-consuming.

Here is the code so far:

function createForm() {
  var form = FormApp.create('Student Survey');  
  
  var questions = getQuestions();
  var ratings = getRatings();
  
  var grid = form.addGridItem();
  
  grid.setTitle("Please answer the following questions about your teacher.");
  grid.setRows(questions);
  grid.setColumns(ratings);
  grid.isRequired();
  
}

Thanks for any help.

1 Answer

It's a little sneaky, but it is there!

For one response per row: Use your GridItem's .setRequired(true);

For one response per column: Check out the GridItem's setValidation() method. It takes a GridValidation parameter you can build with the GridValidationBuilder. See the second section of code below.


Here is your code with both validation types:

function createForm() {
  var form = FormApp.create('Student Survey');  

  var questions = getQuestions();
  var ratings = getRatings();

  var grid = form.addGridItem();

  grid.setTitle("Please answer the following questions about your teacher.");
  grid.setRows(questions);
  grid.setColumns(ratings);

  grid.setRequired(true); //This part is to require one response per row


  //This section requires one response per column.
  var gridValidation = FormApp.createGridValidation()
    .setHelpText("HELP TEXT")
    .requireLimitOneResponsePerColumn()
    .build();

  grid.setValidation(gridValidation);

}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest