function testFunction1() {
const ss = SpreadsheetApp.getActiveSheet();
const form = FormApp.openByUrl(ss.getFormUrl());
var arr = [];
for(i = 0; i<2; i++){
var cell = ss.getRange(2,i+2).getValue();
cell = cell.split(',');
arr.push(cell);
}
var newRes = form
.getItems()[0]
.asCheckboxGridItem()
.createResponse(arr);
form.createResponse().withItemResponse(newRes).submit();
}
When I split each cell, I get:
split cell[0] = ['Paris', 'NYC']
split cell[1] = ['LA']
After pushing the items into arr, I get:
arr = [ ['Paris', 'NYC'], ['LA'] ]
This looks like a 2D array but I then .createResponse(arr) gives the error of "Exception: Invalid response submitted to checkbox grid question."
If I manually enter [ ['Paris', 'NYC'], ['LA'] ] into the .createResponse like this:
function testFunction2() {
const ss = SpreadsheetApp.getActiveSheet();
const form = FormApp.openByUrl(ss.getFormUrl());
var newRes = form
.getItems()[0]
.asCheckboxGridItem()
.createResponse([ ['Paris','NYC'], ['LA'] ]);
form.createResponse().withItemResponse(newRes).submit();
}
then there is no error and the response is added to the Form correctly.
The only thing I can think of is that the cell values are objects and they are not being placed into the 2D array correctly. How can I pass the values from cells into a 2D array correctly?
Adam