I am writing code in which a user can automatically generate a template of lesson and sub-topics. Each lesson will have 10 sub-topics.
I also need to group the rows lesson-wise and topic-wise.
But, I am unable to group the rows lesson-wise and topic-wise. Tried using the macro-recorder, but the code does not work while generating multiple lessons.
EDIT: Working code is updated below.
  function shiftrowgroupdepth() {
  var spreadsheet = SpreadsheetApp.getActive();
  var sheet = spreadsheet.getActiveSheet();
  // start from row 6 and column 2
  var row = 6;
  var col = 2;
  //Ask user for the no. of lessons
  var shlen = Browser.inputBox("Enter no of lessons", Browser.Buttons.OK_CANCEL);
  for (var i = 1; i <= shlen; i++) {
   sheet.getRange(row,col).setValue("Lesson " + i);
   row++;
    Logger.log(spreadsheet.getCurrentCell().getRow())
   sheet.getRange(row, 1, 70, sheet.getMaxColumns()).activate()
  .shiftRowGroupDepth(1);
   // Add sub-topics (1.1, 1.2 ....)
   for (var j=1;j<=10;j++){
     sheet.getRange(row,col).setValue(i+"."+j);
     sheet.getRange(row+1, 1, 6, sheet.getMaxColumns()).activate()
    .shiftRowGroupDepth(1);
     row=row+7;
     }    
  }
};
