Reputation: 11
I am using Google Apps Script to add questions from a Google Sheets into a Google Form. The lists are read from two separate arrays and added as individual Grid type questions. I also set the Sheet as the destination for the Form results.
When I run the script, the Form gets updated perfectly. If there are 10 items to be added, 10 questions are added to the Form. However, in the Form Responses sheet that is linked, there are often times additional columns titled " [Row 1]" that are added. The number of additional columns and their position change what seems like every other time I run the script. I haven't been able to pick up on any patterns.
I do know that "Row 1" appears as the default first item in a Grid type question when creating the question in the Form's UI. I'm not sure if that has anything to do with it. FYI - grid items allow multiple rows of questions to be added but I am only adding one question. I know there is a multiple choice grid type but I do not like the formatting of it.
As a workaround, I've created a script to delete all of these additional columns but I would really like to figure out what is actually happening.
Any ideas on what is happening?
Here is part of my code:
function editForm()
{
var setupSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Setup'); //Create variable for the Setup sheet
var metricSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Final Metric Statements'); //Create variable for the Metric Statements sheet
var form = FormApp.openById(setupSheet.getRange("D1").getValue()); //Open form using the form ID from the setup sheet
var pageFour = form.addPageBreakItem().setTitle('Questions');
var emotLen = 0; //Counter for sub-emotion items
var featLen = 0; //Counter for sub-feature items
//Count number of items for first list
while (((metricSheet.getRange("C"+ (emotLen+2)).getValue()) != "") && ((metricSheet.getRange("C"+ (emotLen+2)).getValue()) != "#N/A")) //Go through sub-emotion column until a blank cell
{
emotLen++; //Increase the counter
}
//Count number of items for second list
while (((metricSheet.getRange("D"+ (featLen+2)).getValue()) != "") && ((metricSheet.getRange("D"+ (featLen+2)).getValue()) != "#N/A")) //Go through sub-feature column until a blank cell
{
featLen++; //Increase the counter
}
if (emotLen > 0)
{
var emotRng = metricSheet.getRange(2,3,emotLen); //Create a range for sub-emotions based on number of items and column
var emotArray = emotRng.getValues(); //Copy the items into an array
for (i=0; i <= (emotLen-1); i++)
{
var emotItem = form.addGridItem();
emotItem.setRows(emotArray[i]);
emotItem.setColumns(['Strongly Disagree', 'Disagree','Slightly Disagree', 'Neither Disagree or Agree', 'Slightly Agree', 'Agree', 'Strongly Agree', 'N/A']);//Add column header
emotItem.setRequired(true);
}
}
if (featLen > 0 )
{
var featRng = metricSheet.getRange(2,4,featLen); //Create a range for features based on number of items
var featArray = featRng.getValues(); //Copy the items into an array
for (i = 0; i <=(featLen-1); i++) //Go through all items in the array
{
var featItem = form.addGridItem();//Add item to survey
featItem.setRows(featArray[i]); //Add row item
featItem.setColumns(['Strongly Disagree', 'Disagree','Slightly Disagree', 'Neither Disagree or Agree', 'Slightly Agree', 'Agree', 'Strongly Agree', 'N/A']);//Add column header
featItem.setRequired(true);
}
}
//deleteRowColumns();
//Logger.log(emotLen, emotArray, featLen, featArray); //Logger used for debugging
}
And here is a screenshot of the Form Responses sheet with the additional column:
Upvotes: 1
Views: 173
Reputation: 15357
I have taken the liberty of reporting this on Google's Issue Tracker for you, detailing the behaviour:
You can hit the ☆ next to the issue number in the top left on the page which lets Google know more people are encountering this and so it is more likely to be seen to faster.
Upvotes: 2