Getting Javascript error - 'undefined is not an object'
I am relatively new to working with scripts in InDesign and have been reading "InDesign CS5 Automation Using XML and Javascript" by Grant Gamble. There's a script I'm trying to execute to update a table in a publication, and I keep getting a Javascript error (Error number: 21 Error String: undefined is not an object) when it executes a function. The error dialog points to the line of code I've bolded below:
function updateTables(){
var doc = app.activeDocument;
for (var i =0; i < doc.pages.length; i++){
var currentPage = doc.pages[i];
var currentFrame;
if(currentPage.textFrames.length > 0 && currentPage.textFrames[0].tables.length > 0){
}
else{
continue;
}
var tableCount = currentFrame.tables.length;
if(tableCount > 0){
var currentTable = currentFrame.tables[0];
var rowCount = currentTable.rows.length;
var currentCuisine = currentFrame.paragraphs[0].contents.replace("\n", "");
for (var j = 0; j < rowCount; j++){
var currentRow = currentTable.rows[j];
var currentCourse = currentRow.cells[0].contents;
var currentKey = currentCuisine + currentCourse;
if(currentKey in g.objDates){
currentRow.contents = g.objDates[currentKey];
}
}
}
}
//
I appreciate any guidance on debugging it. Thank you!
