I try to update a Google Form from Google Sheets. There is one type of question that I can't find how to activate using Google Apps Script: 'Multiple choice grid'
As you can see in the picture, the is only one option for 'multiple choice'.
I found this article that presents the available types, maybe it can assist you: https://developers.google.com/apps-script/reference/forms/item-type
CODE VERSION #2:
const populateGoogleForms1 = () => {
const GOOGLE_SHEET_NAME = 'sheet_name';
const GOOGLE_FORM_ID = 'form_path';
const ss = SpreadsheetApp.getActiveSpreadsheet();
const [header, ...data] = ss
.getSheetByName(GOOGLE_SHEET_NAME)
.getDataRange()
.getDisplayValues();
const choices = {};
header.forEach((title, i) => {
choices[title] = data.map((d) => d[i]).filter((e) => e);
});
FormApp.openById(GOOGLE_FORM_ID)
.getItems()
.map((item) => ({
item,
values: choices[item.getTitle()],
}))
.filter((values) => values)
.forEach(({ item, values }) => {
switch (item.getType()) {
case FormApp.ItemType.CheckboxGrid:
item.asCheckboxGridItem().setChoiceValues(values);
break;
case FormApp.ItemType.Checkbox:
item.asCheckboxItem().setChoiceValues(values);
break;
case FormApp.ItemType.Grid:
item.asGridItem().setChoiceValues(values);
break;
case FormApp.ItemType.List:
item.asListItem().setChoiceValues(values);
break;
case FormApp.ItemType.MultipleChoice:
item.asMultipleChoiceItem().setChoiceValues(values);
break;
case FormApp.ItemType.MultipleChoiceGrid:
item.asMultipleChoiceGridItem().setChoiceValues(values);
break;
default:
// ignore item
}
});
ss.toast('Google Form Updated !!');
};

