nellygrl
nellygrl

Reputation: 657

getID() Not Recognized

I am coding a script that lets Google Sheets track the progress of an author's novel being written in Google Drive.

I am trying to calculate the word count of a given document and push it into an array in the code below:

// Gets each chapter's word count and pushes it into the numberTitleCount array.

for(c in files){
  var counter = 0;
  var ID = files[c].getID();
  var doc = DocsList.getFileById(ID);

  var text = doc.getText();
  var textArray = text.split(" ");
  counter = textArray.length;
  numberTitleCount[c].push(counter);
}

The issue is, when I run the script, an error occurs. This is the error:

TypeError: Cannot find function getID in object File. (line 20, file "commentCount")

I'm not sure what the error is. files is an array of files so calling files[c].getID() should get the indicated file's ID, but no such luck. I know the array is fine as before I tried adding the word count functionality, I used the same array to get chapter numbers and titles successfully.

Any input into this issue would be greatly appreciated!

~Noelle

Upvotes: 0

Views: 1527

Answers (1)

Phil Bozak
Phil Bozak

Reputation: 2822

If you use the autocomplete feature of the script editor, you would be able to catch this issue more easily. (Ctrl + Space).

The issue is that the function is called getId(), not getID(). Documentation.

Upvotes: 1

Related Questions