Sunday, November 2, 2008

Best practice: Looping on a document collection

This is the loop I always use on document collections/views. You have to check for deleted/valid documents, and often also for conflicts. You can use some nested IF...THEN...ELSE - but this will make the code har to read. Instead I use a simpel goto construction - and with this you can easily add more checks to the code...

Do Until doc Is Nothing
If doc.IsDeleted Then Goto NEXTDOC
If Not doc.IsValid Then Goto NEXTDOC
If doc.HasItem( "$Conflict" ) Then Goto NEXTDOC

NEXTDOC:
set doc = coll.getNextDocument( doc )
loop

0 comments:

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.