"Cannot retrieve the next object: iterators has reached the end" -- only works for some users???

16 views
Skip to first unread message

Alexis T

unread,
Jun 23, 2019, 2:12:51 AM6/23/19
to Google Apps Script Community
I am working with an elementary school to help ease data entry. So created a script to send data from a google-sheet named 'FORM' to another google-sheet named 'Data' by the click of a button.

I put their main data sheet in the drive, as well as many other google-sheets for teachers to submit grades (each teacher will have their own form). It is on a team drive and the 'manager' is 'Anna'. She shared the drive with me (a non school district email) and 4 others (school district emails). We all have 'Editing' privileged. 

I'm running into the error above! It works for me..at home and while I am logged in at the school via Ethernet. 'Anna' can send data to the data sheet no problem..everyone else is running into the issue of iterators have reached the end.  I see the script is shared with them and I have no idea what to do!! The ones who cannot are using Chromebooks with a Securly browser extension..maybe it's that?? We even tried them signing in on personal laptops at home outside of the wifi network at school. (which I thought was the original error) but the still get the above error.

Here's the script:



function TransferGradesA() {
    
  var sh=SpreadsheetApp.getUi();
  var response=sh.alert("Submit Grades", "Please ensure teacher and test are correct. \r\n Are you sure you want to submit grades?", sh.ButtonSet.YES_NO);
  
  //if response is yes
  if(response==sh.Button.YES)
  {
    addGradesAttempt();
  }
  //else reponse is no
  else 
  {
    sh.alert("Please Try Again Later");
  }
  
  clear();
}

//clear current grades

function clear() 
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];

  var range = sheet.getRange("C7:C30");
  range.clearContent();
}

function addGradesAttempt() {
  
  var destinationFile = DriveApp.getFilesByName("Main Data Form").next();
  //var destinationFile = SpreadsheetApp.openByUrl("");
  var destination = SpreadsheetApp.open(destinationFile).getSheetByName("Data");
  
  
 
  var sourceFile = DriveApp.getFilesByName("K Grade Form").next();
  //var sourceFile = SpreadsheetApp.getActive();
  var source = SpreadsheetApp.open(sourceFile).getSheetByName("Form"); 

  
  
  // Teacher name is stored in B3, get the range, then get the first value
  var teacher = source.getSheetValues(3, 2, 1, 1)[0][0];
  
  // Test is stored in B5
  var testName = source.getSheetValues(5, 2, 1, 1)[0][0];
    
  // In the destination sheet, locate the column that stores the test name
  
  var testColumn = 0;
  var testNames = destination.getSheetValues(1, 4, 1, 300); // This will handle up to 300 individual test columns. Increase this number if needed
  
  for (var i = 0; i < testNames[0].length; i++) {
    if (testNames[0][i] == testName)
    {
      testColumn = i + 3 // Add 6 to the result since we started searching at 6
      break; // Break out of the loop early as we already found a hit
    }
  }
  
  // Jump to the end of the Destination sheet to append values
   var testScoreResults = destination.getDataRange().getValues();

  
  // Loop through the grades in the source sheet, then add them as new entries in the destination sheet
  
  var testScores = source.getSheetValues(7, 2, 35, 2) // 35 rows means up to 35 scores can be added at once. Increase if needed
  

  for (var i = 0; i < 35; i++) {
    if(testScores[i][0] != "") { // Only do work if there's a name

      
      // Find the row that contains this teacher/student combination
      for (var j = 0; j < testScoreResults.length; j++) {
        if (testScoreResults[j][2] == testScores[i][0] && // Match the student name
            testScoreResults[j][4] == teacher) {          // Match the teacher name
          
          // Set the test score
          testScoreResults[j][testColumn] = testScores[i][1];
          break; // Stop processing for this student as we have a match
        }
        
      } 
    } 
  }  

  // Save the results back to the spreadsheet
  destination.getDataRange().setValues(testScoreResults);
  
  // Save all the results
  SpreadsheetApp.flush();
}
Reply all
Reply to author
Forward
0 new messages