Is there a way to speed up this Google Apps Script HTML interface?

I’ve got this project which loads an HTML page and pulls info from a Google Sheet and displays it on the webpage. The code works fine, but it takes a while to pull from the input field, run the necessary functions and return a response. Are there some things I could be doing to improve the speed?

Here is the script I’m running on the HTML page:

            <script>
                // If enter pressed, click button
                var input = document.getElementById("studentNameID");
                input.addEventListener("keypress", function(event) {
                if (event.key === "Enter") {
                    event.preventDefault();
                    document.getElementById("submit-btn").click();
                }
                });

                function get_student_name_or_ID() {

                    // Get student name or ID and pass it to function.
                    var studentNameOrID = document.getElementById("studentNameID").value;
                    google.script.run.withSuccessHandler(updateSheet).getInfo(studentNameOrID);
                    document.getElementById('studentNameID').value = "";
                    document.getElementById("not-found").innerHTML = "<b> Loading... </b>";
                }

                function updateSheet(returnedInfo) {
                    if (returnedInfo == "Record not found.") {
                        document.getElementById("not-found").innerHTML = "<b>" + returnedInfo + "</b>";
                    }
                    else {
                        document.getElementById("not-found").innerHTML = " ";
                        document.getElementById("name").innerHTML = "Name: " + returnedInfo[3] + " " + returnedInfo[2];
                        document.getElementById("student-ID").innerHTML = "Student ID: " + returnedInfo[1];
                        document.getElementById("grade").innerHTML = "Grade: " + returnedInfo[4];
                        document.getElementById("item-requested").innerHTML = "Item Requested: " + returnedInfo[6]
                        document.getElementById("teacher-points").innerHTML = "Points from teachers: <br>   " + 
                            returnedInfo[7] + ": <br>   "  + 
                            returnedInfo[8] + ": <br>   "  +
                            returnedInfo[9] + ": <br>   "  +
                            returnedInfo[10] + ": <br>   "  +
                            returnedInfo[11] + ": <br>   "  +
                            returnedInfo[12] + ": ";
                        document.getElementById("point-values").innerHTML = " <br>" +
                            returnedInfo[15] + "<br>" +
                            returnedInfo[16] + "<br>" +
                            returnedInfo[17] + "<br>" +
                            returnedInfo[18] + "<br>" +
                            returnedInfo[19] + "<br>" +
                            returnedInfo[20] + "<br>";
                        document.getElementById("comments").innerHTML = "<br>" +
                            returnedInfo[21] + "<br>" +
                            returnedInfo[22] + "<br>" +
                            returnedInfo[23] + "<br>" +
                            returnedInfo[24] + "<br>" +
                            returnedInfo[25] + "<br>" +
                            returnedInfo[26] + "<br>";
                        document.getElementById("total-teacher-points").innerHTML = "Total Teacher Points: " + returnedInfo[13];
                        document.getElementById("incentives-points").innerHTML = "Incentives Points: " + returnedInfo[14];
                    }
                }
            </script>

And here is the gscript that is running to pull from the spreadsheet. It’s a few functions;

function getInfo(textInput) {
  var ss = SpreadsheetApp.openById('1T8mx1eYGnJmol5uU_FQOd4qdpiSyX71LYRy5YE71iEY');
  var processingSheet = ss.getSheetByName('Processing');
  var lastRow = processingSheet.getRange("A2").getDataRegion().getLastRow();
  var processingRange = processingSheet.getRange("A2:O" + lastRow).getValues();

  if (JSON.stringify(processingRange).includes(textInput)) {
    for (i = 0; i < lastRow; i++) {
      if (textInput == processingRange[i][1] || textInput == processingRange[i][1]) {
        
        // append points to end of array before returning
        for (var k = 8; k <= 13; k++) {
          processingRange[i].push(colorCodes(processingSheet.getRange(i + 2, k).getBackground()))
        }
        for (var k = 7; k <= 12; k++) {
          processingRange[i].push(commentsFunc(processingRange[i][k], processingRange[i][1]))
        }
        Logger.log(commentsFunc(processingRange[i][7], processingRange[i][1]))
        Logger.log(processingRange[i]);
        return processingRange[i];
      }
    }
  }
  else {
    return "Record not found.";
  }
}

function commentsFunc(teacherName, studentID) {
  var ss = SpreadsheetApp.openById('1T8mx1eYGnJmol5uU_FQOd4qdpiSyX71LYRy5YE71iEY');
  var teacherFormResponses = ss.getSheetByName("Teacher Form Responses");
  var teacherFormRange = teacherFormResponses.getRange("A2:G" + teacherFormResponses.getLastRow()).getValues();
  var teacherFormLastRow = teacherFormResponses.getLastRow();

  // if teacher name and student name match what's on the sheet, then return the comment.
  for (var k = 0; k < teacherFormLastRow - 1; k++) {
    if (teacherName == teacherFormRange[k][6] && studentID == teacherFormRange[k][5]) {
      Logger.log(teacherFormRange[k][4])
      return teacherFormRange[k][4];
    }
    else if (k == teacherFormLastRow - 2) {
      Logger.log(teacherName, studentID)
      return "";
    }
  }
}

function colorCodes(colorCell) {
  if (colorCell == "#ffffff" || colorCell == "#ffff00") {
    return "Not submitted"
  }
  if (colorCell == "#ff0000") {
    return "0"
  }
  if (colorCell == "#9900ff") {
    return "1"
  }
  if (colorCell == "#ff9900") {
    return "2"
  }
  if (colorCell == "#00ffff") {
    return "3"
  }
  if (colorCell == "#00ff00") {
    return "4"
  }
}

I have no doubt that there are better ways of coding and best practices that I’m not aware of. Please feel free to offer any suggestions in this regard.

I appreciate any assistance. Thanks.

New contributor

Jason Vigil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật