我有一个为我编写的google脚本,它已经工作了几年,现在当我尝试运行它时,出现此错误“ TypeError:无法从未定义中读取属性“ length”。(第20行,文件.....“。程序员不再可以为我提供帮助。
该脚本的目的是汇编教师正在教授的课程列表,并通过电子邮件将其确认以确认信息正确。
这是脚本
//Creating a function to obtain the location of the required columns on the sheet
function Columns(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet for Emails");
var data = sheet.getDataRange().getValues();
var id = /@/;
var idRow;
var len = data.length;
//Searching for the ID character '@'
for(i=0; i<len; i++)
{
if(id.test(data[i][0]))
{idRow = i; break;}
}
len = data[idRow].length;
//Going through every column of ID row and matching it to the required columns
for(i=0; i<len; i++)
{
id = data[idRow][i].slice(1); //Slicing off the ID character
switch(id) //Matching the required columns to the ids
{
case '1': this.Instructor = i;break;
case '2': this.Course = i;break;
case '3': this.Classroom = i;break;
case '4': this.Term = i; break;
case '5': this.Days = i;break;
case '6': this.Time = i;break;
case '7': this.CourseID = i;break;
case '8': this.Dates = i;break;
case '9': this.InstructorEmail = i;break;
case '10': this.ExtraSessions = i; break;
case '11': this.Notes = i; break;
case '12': this.FolderID = i;break;
}
}
}
function AskProfessorRecord(){
// Opening the required sheet
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet for Emails");
// Getting the range of data
var range = ss.getDataRange();
// Getting the values
var values = range.getValues();
//Array of Professor Names
var ProfessorNames = ["Init"];
// Holds the email id of the professor
var ProfessorEmailID;
//Column Object
var cols = new Columns();
var tempName
var tempIndex
//** Section Start **
// This section goes through the sheet and creates an array
// with the all the professors' names
for(i = 2; i < values.length; i++)
{
// Checking the instructor name of the i row
tempName = values[i][cols.Instructor];
tempIndex = ProfessorNames.indexOf(tempName);
if(tempIndex == -1){
ProfessorNames.push(tempName)
}
}
// ** Section End **
var html
var body
var flag = 0
var FirstSpaceIndex
var FirstName
for(j = 1; j < ProfessorNames.length; j++){
html = "<DOCTYPE html><html><body>";
for(i=2; i < values.length; i++){
if(flag == 0 && values[i][cols.Instructor] == ProfessorNames[j]){
FirstSpaceIndex = ProfessorNames[j].indexOf(" ");
FirstName = ProfessorNames[j].slice(0,FirstSpaceIndex)
body = "Hello "+ FirstName + ",<br><br>" +
"Media Services is in the process of scheduling class recordings for the next quarter. " +
"The classes we have scheduled for you are listed below. " +
'Please <strong style="color:red;"> check the location and date range</strong> of your class schedule. ' +
"You only need to respond if there is a modification to the location or dates or if you do not want the classes recorded.<br><br>"
flag = 1;
ProfessorEmailID = values[i][cols.InstructorEmail];
}
if(flag == 1 && values[i][cols.Instructor] == ProfessorNames[j]){
body = body + "<br><br>" +
values[i][cols.Course] + "<br>  " +
values[i][cols.Term] + "<br>  " +
values[i][cols.Days] + "<br>  " +
values[i][cols.Time] + "<br>  " +
"<strong style='color:red;'>Location: </strong>" +
values[i][cols.Classroom] +
"<br>  " + "<strong style='color:red;'>Date Range: </strong>" +
values[i][cols.Dates] + "<br>  " +
values[i][cols.CourseID];
}
}
body = body + "<br>-- <br>" +
"Joel Bennett <br>" +
"XYA University <br>" +
"Office: 428.222.53338";
// HTML body is closed
html = html + body + "</body></html>";
flag = 0;
// The email is sent to the professor
MailApp.sendEmail({
to: ProfessorEmailID,
subject: 'Classroom Recording Schedule',
htmlBody: html });
}
}