Search DominoPower's 11,441 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
A Fix for folders and documents (continued)

It would be tempting to use the document collection count, in code like this:

For i = 1 To doccoll.count
Set doc = doccoll.GetNthDocument(i)
If doc.folderreferences(0) <> "" Then 'doc is in at least one folder
Call doccoll.deletedocument(doc) 'pulls it from the collection
End If
Next

Sadly, this won't work, for two reasons. The For loop grabs the doccoll.count value when the For statement is executed the first time. Say there are 10 documents in the collection. While executing the loop, you remove documents from the collection. So the actual value of doccoll.count goes down by one, each time you circulate the loop.

But the For statements does not dynamically check i against doccoll.count -- for, I guess, performance reasons, it actually checks it against the value it grabbed at the start, which does not change while the loop executes. You remove 2 documents from the collection - there are now 8 left. But the For loop still expects to iterate to 10, so when it runs the 9th iteration, the if doc.folderreferences(0) line will cause an 'Object Not Set' error, because there is no 9th document in the collection any more.

The other fault is this: remove the 6th document, and what was the 7th becomes the sixth. But the loop, having processed the sixth, the code processes the now 7th document, and so skips one -- the one that moved from 7th to 6th when the old 6th one was removed.

I'm going back to bed. But before I do, I should also point out that Peter will still get one result he didn't expect. He says he told his agent to run on selected documents. However the code (line 8 in the complete example above) gets all the documents in the database. The agent selection specification is really for simple and formula agents, which are run once in their entirety for each selected document -- which also explains the presence of the 'Run Once' option.

LotusScript agents are always run just once, and do their own selection of documents. They have the ability to use NotesDatabase.UnprocessedDocuments to find the selected documents -- or new/modified documents if that's how the agent runs -- but the actual document selection is up to the agent code, and not up to Notes.

The Designer help says it all:

LotusScript and Java agents run once. You supply the search criteria and the iteration through the language constructs. Search criteria applied through the agent interface are effective only through UnprocessedDocuments in NotesDatabase (LotusScript) or UnprocessedDocuments in AgentContext (Java).

Now I really am going back to bed.

David Gewirtz is the author of How To Save Jobs and Where Have All The Emails Gone? For more than 20 years, he has analyzed current, historical, and emerging issues relating to technology, competitiveness, and policy. David is the Editor-in-Chief of the ZATZ magazines, is the Cyberterrorism Advisor for the International Association for Counterterrorism and Security Professionals, and is a member of the instructional faculty at the University of California, Berkeley extension. He can be reached at david@zatz.com and you can follow him at http://www.twitter.com/DavidGewirtz.


« Previous  ·  1  ·  2
Other articles you might like
Home > Strategies > Email Management (60 articles)
   Using the Notes Client with Gmail
   Using the Notes client with Hotmail (or not)
   Is English-only a viable mail management strategy?
Home > Tips & Techniques (102 articles)
   More about Domino log files
   Why your log.nsf might not be purging properly
   A faster way to repair corrupted server files
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
Learn Domino Designer 8.5 for free
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Latest Lotus Headlines
Xpages not loading? JVM errors? - Solution
How to implement an iCalendar feed into your Notes calendar with XPages
DWA Hotfixes for Domino 8.5.1FP1 - A Gotcha
IBM Adds DB2 to Lotus Foundations SMB Package
SNTT : XPages onclick Ghosts in the machine
Ports used by Lotus Sametime 8.5 servers
Exploring a Domino Date Bug
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
OutlookPower: More about disappearing text
-- Advertisement --

Find unused Lotus Notes groups and clean up your address book
Have you ever wanted to get rid of old Lotus Notes groups that were cluttering up your address book, but you weren't sure if they were used? Find Unused Groups can help.

Find Unused Groups will check your ACL, mail, multi purpose and server groups to help you determine if they are used, and who uses them.

Learn how to easily clean up your address book.

-- Advertisement --

Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.

Register by April 10 to save $200.
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login