I have created a google spreadsheet to automatically convert into a google form, so i don't have to manually enter all the questions into the google form.
I am writing google app script and managed to get all the questions.I am trying to divide the form in to sections depending on the first column of the sheet. So if the first column is "1" questions corresponding to it should be on the first section and if it is "2" it should create another section.And so on.
How can i do that? what will be the code? I have attached the google sheet as here Google spreadsheet
function myFunction()
{
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var range = ss.getDataRange();
var data = range.getValues();
var numberRows = range.getNumRows();
var numberColumns = range.getNumColumns();
var firstRow = 1;
var form = FormApp.openById('1hIQCLT_JGLcvjz44vXTvP5ziia6NnwCqWBxYT4h2uCk');
var items = form.getItems();
var ilength = items.length;
for (var i=0; i<items.length; i++)
{
form.deleteItem(0);
}
for(var i=0;i<numberRows;i++)
{
Logger.log(data);
var questionType = data[i][0];
if (questionType=='')
{
continue;
}
//choose the type of question from the first column of the spreadsheet
else if(questionType=='1')
{
var rowLength = data[i].length;
var currentRow = firstRow+i;
var currentRangeValues = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1').getRange(currentRow,1,1,rowLength).getValues();
var getSheetRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1').getDataRange();
var numberOfColumnsSheet = getSheetRange.getNumColumns();
var numberOfOptionsInCurrentRow = numberOfColumnsSheet;
var lastColumnInRange = String.fromCharCode(64 + (numberOfOptionsInCurrentRow));
var range_string = 'C' + currentRow + ":" + lastColumnInRange + currentRow;
var optionsArray = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1').getRange(range_string).getValues();
var choicesForQuestion =[];
for (var j=0;j<optionsArray[0].length;j++)
{
choicesForQuestion.push(optionsArray[0][j]);
}
form.addMultipleChoiceItem().setTitle(data[i][1]).setHelpText("").setChoiceValues(choicesForQuestion).setRequired(true);
}
else
{
continue;
}
}
form.addParagraphTextItem()
.setTitle('Please specify and attach relevant documents'); // add the text question at the last
form.addPageBreakItem().setTitle('Identity - Asset Management').setHelpText("")();
}
{}
should all line up vertically so that it's visually easy to tell what's in the same code blocks. This also means everything inside the code blocks should be tabbed (well, 4 spaces). Those two fixes would make this question much more readable. - NoseKnowsAll