jasonjurotich / JJ-GAS

A collection of Google Apps Script code (GAS) for Google Apps and Classroom
34 stars 10 forks source link

Issue with the grid item columns #2

Open chCharly opened 4 years ago

chCharly commented 4 years ago

When you set the second row in the template sheet for setting the correspondent columns of the grid it didn't work. So just added some new 'cr', 'ro' and 'op' variables in the 'for loop with x' section to call the second row instead of the first like this:

for(var x=0;x<nr;x++){ // Beginning of for loop with x var i = d[x][0]; var cr = 1 + x; var ro = s.getRange(cr, 8, 1, 10); var op = ro.getValues(); var cr2 = 2 + x; var ro2 = s.getRange(cr2, 8, 1, 10); var op2 = ro2.getValues(); if(i==''){continue;}

Then just called those new variables instead in the 'arr2' variable in the GRID and CHECKGRID sections like this:

var arr2 = []; for (q=0; q<op2[0].length; q++){ if (op2[0][q] !== '') {arr2.push(op2[0][q]);} }

I dont know if there is a better way to do this but I think this works...

marcosruiz commented 2 years ago

There you have my solution. I think is almost the same.

    else if (i =='GRID') {
        // Rows (second row)
        var ro2 = s.getRange(cr+1, 8, 1, 10);
        var op2 = ro2.getValues();
        var arr1 = []; 
        for (q=0; q<op2[0].length; q++){ 
          if (op2[0][q] !== '') {arr1.push(op2[0][q]);} 
        }
        // Columns (first row)
        var arr2 = []; 
        for (q=0; q<op[0].length; q++){ 
          if (op[0][q] !== '') {arr2.push(op[0][q]);} 
        }
        f.addGridItem().setTitle(d[x][1]).setHelpText(d[x][2]).setRequired(true).setRows(arr1).setColumns(arr2);
    }

In CHECKGRID would be the same.