jamietr1 / google-docs-writing-tracker

Automation scripts to track writing in Google Docs
187 stars 39 forks source link

Cannot retrieve the next object: iterator has reached the end. (line 10, file "Code") #31

Open coes123 opened 9 years ago

coes123 commented 9 years ago

Hi,

The WritingStats script had been working fine for months but a couple of days ago I got the DocsList deprecated error. Apparently I had forgotten to update it since December (!!). Anyway, I copied and pasted the new code but now I get this error and I have no idea why or where to begin.

Cannot retrieve the next object: iterator has reached the end. (line 10, file "Code")

Line 10 is: var SANDBOX_ID = DriveApp.getFoldersByName(SANDBOX).next().getId();

My folder path is: Writer/Sandbox Writer/Sandbox/Earlier

Daily Almanac is working fine. Everything was fine!!

Could someone help please?

coes123 commented 9 years ago

Well, it looks like I won't be able to use this wonderful script for no reason... I deleted all script files, renamed my Writing folder and even used today's WritingStats release and I'm getting the same errors... I'm sad.

mythos1717 commented 9 years ago

Hi coes123,

After having some issues with the code and realizing that it was probably the older version, I updated to this new one. I got the same error as you. Here's how I fixed it.

In your "Google Writing Tracker Data" spreadsheet (or whatever you call it) make you only have the name of the folder that is your "Sandbox" typed in, and not the full path to it. In the old version, the code used the path. It looks like this version (which uses a new command) does not need to access the full path to find the folder. Also, make sure you do the same for your "Snapshot" folder. Otherwise you will get the same error on the next line.

Also there's a line of code that still has a deprecated command on line 530, that can be commented out or deleted. Here's what the line of code looks like: var doc2 = DocsList.getFileById(file.getId()).getContentAsString();

I hope that helps.

Just an FYI, I'm not the developer, just someone who figured out what the problem was. The developer of this script does not have a lot of time to provide support for this script since he has a day job and also works on the side. Please keep that in mind when posting about issues.

jamietr1 commented 9 years ago

I believe that @mythos1717 is correct. In fact, I'd swear that I documented that somewhere, so I just checked the README and sure enough, toward the end of the first bullet is the following:

The location of the Snapshot folder should refer only to the folder name rather than the full path. If you had, for instance "Sandbox\Earlier" as your snapshot folder name, it should be changed to "Earlier" for it to work correctly.

I know it is kind of buried in there. Sorry about that, and for any confusion.

delsdog commented 9 years ago

Thanks @mythos1717 that fixed things for me.

rustuptwist commented 9 years ago

@mythos1717 or anyone else lurking around in this forum. Does the 'Sandbox' folder need to be in a specific folder, e.g. Scripts... or something? As I have my folder named 'TheTablet' correctly inputed in the spreadsheet but I am getting the: 'Cannot retrieve the next object: iterator has reached the end. (line 10, file "Code")' error message. So I am wondering what I may have done wrong..? Sandbox folder name: 'TheTablet' & Snapshot.

Update: it seems that the 'Snapshot' folder needs to be named 'Earlier' Is that the case, since when I name it that I no longer get the error message. thx

mythos1717 commented 9 years ago

Hi @rustuptwist

If your folder is named "Earlier" than that's what you should put in the spreadsheet. If not, use whatever you did name it. I hope that helps. :)

rustuptwist commented 9 years ago

Hi @mythos1717 My folder was called something else but I kept getting the error when I used that name. I changed it to 'Earlier' and the errors stopped.

mythos1717 commented 9 years ago

@rustuptwist

It works like this. The documents that you write in should go in the "Sandbox" folder. When the script runs (as it should every night-if you've setup the triggers correctly). The files get copied to the "Earlier" folder. This is how (later) the script can calculate the number of new words in your documents.

If you have no documents in your "Earlier" folder than the script is either not working right, or the triggers are not setup correctly.

I hope that helps a little bit.

creativeblip commented 9 years ago

Hi. I also keep getting this error code with the scripts. I've followed the setup instructions (multiple times). My Sandbox folder is just in my base Google Drive, and my Earlier folder is in the Sandbox folder. My Sandbox Location cell says Sandbox and my Snapshot Location cell says Sandbox/Earlier. I get the following error code:

Cannot retrieve the next object: iterator has reached the end. (line 11, file "Code")

I finally resorted to hardcoding the folder IDs into the script codes, and that seems to have fixed it. So the problem for me is apparently in this function working:

var SANDBOX_ID = DriveApp.getFoldersByName(SANDBOX).next().getId();

Any thoughts on why?

mythos1717 commented 9 years ago

Hi @creativeblip I think the problem is the "Sandbox/Earlier" that you have in your Snapshot cell. Change it to just "Earlier" and then try it. That's what I did to fix the problem.

I had also read through the instructions multiple times and ended up making this mistake. I think that section of the instructions is easily misunderstood.

creativeblip commented 9 years ago

Ahhhhh! Thanks @mythos1717, that fixed it! :)

mythos1717 commented 9 years ago

Yay! :+1:000

BlaineMoore commented 8 years ago

Guess I should have checked the issues here first...spent an hour troubleshooting this earlier today and obviously came to the same conclusion here. I'm using Scrivener to populate my data, so I had to just put "Drafts" into the sandbox cell and "Earlier" into the other cell. It'd be nice if I could use multiple subfolders so I could work off of multiple Scrivener files without having to worry about syncing issues, but as is i think I'm stuck w/one since they'll always have the "Drafts" folder...

developertop3 commented 7 years ago

okay