Could someone help me troubleshoot this issue I'm encountering in Google Sheets Apps Script: "TypeError: Cannot read properties of undefined (reading 'length')"? I found this script on YouTube and tried to implement it.
Below is the code snippet:
function showInputBox(){
var ui = SpreadsheetApp.getUi();
var input = ui.prompt("Please enter your Name.", ui.ButtonSet.OK_CANCEL);
if(input.getSelectedButton() == ui.Button.OK){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getSheetByName("original");
var data = ws.getRange("A2:G" + ws.getLastRow()).getValues();
var userSelectedRep = input.getResponseText().toLowerCase();
var newData = data.filter(function(r){ return r[2] == userSelectedRep });
var newWs = ss.insertSheet(userSelectedRep);
newWs.getRange(2, 1, newData.length, newData[0].length).setValues(newData);
}