ViewEntryCollection loop code failing on server within scheduled agent

i am trying to loop through a view entry collection - my agent works if i run it manually, and if i run the code using an external development tool (RSA). the code stops after processing one entry in the VEC when the agent runs on a schedule on the server…any ideas why?

the code must be fine as it works in other circumstances but here it is anyway…

ViewEntryCollection vec = view.getAllEntries() ;

ViewEntry entry = vec.getFirstEntry() ;

while( entry != null ) {

Document doc = entry.getDocument() ;

//do stuff

entry = vec.getNextEntry() ;

}

i’m thinking this must be a “quirk” - but anyone else had a similar problem?

(am waiting to get access to logs to see if i can see any errors…)

Subject: ViewEntryCollection loop code failing on server within scheduled agent

Hello Helen,

try changing entry = vec.getNextEntry() ;

to entry = vec.getNextEntry(entry);

Best Regards,

Munish Kaushik

Subject: RE: ViewEntryCollection loop code failing on server within scheduled agent

Thanks Munish - how likely is this to work? why should it work?..

I only ask because the code runs fine in all environments, and when run manually. It’s only on the production/live server that the agent stops running!! I don’t want to have to deploy something that might not work or something that I don’t really understand…

Thanks in advance for your explanation!!!

Subject: RE: ViewEntryCollection loop code failing on server within scheduled agent

Not sure why it appear to work when run manually - there are many reasons for this.

What Munish has said is the correct way to return the loop:

Set ve=vcol.getNextEntry(ve)

where ve is the current entry

Check the method in designer help for more information.

Would need to see more code to work out why not running on schedule. Have you included any UI/front end classes for example?

Subject: RE: ViewEntryCollection loop code failing on server within scheduled agent

thanks Melissa…

the code is the same when run manually and when run on schedule… when i run it manually i use an action button as follows:

Sub Click(Source As Button)

Dim ss As New NotesSession

Dim db As NotesDatabase

Dim agent As notesagent



Set db=ss.CurrentDatabase

Set agent=db.GetAgent("ProcessNotification")

Call agent.RunOnServer

End Sub

so it is simply runnning the same scheduled agent…

I don’t understand why:

Set ve=vcol.getNextEntry(ve)

would be the “correct” way to return the loop - i have looked at the designer help documentation and there’s nothing to say that this is more correct than not specifying the current document - their example of using the method without passing in the current entry is exactly the same as in my agent…

i know that it is worth a try, but as i said in my previous post, my customer won’t be happy with me requesting another deployment only to find it’s still not working! so that is why i am wanting to be a little more sure this will fix my problem, maybe through a reason why it should work or an example of where this has fixed a similar problem…

Thanks again!

Subject: RE: ViewEntryCollection loop code failing on server within scheduled agent

Dear Helen

You posted the code that calls the agent not the agent code!

As you pointed out, calling the agent with ‘runOnServer’ from an action button should be the same as when it runs on a schedule on the server. There shouldn’t be a difference in the result.

I must admit I didn’t realise that you could leave that parameter empty! I’m so used to avoiding infinite loops in the NotesDocumentCollection that I just automatically reference the current entry as a matter of form.

I have written a number of scheduled agents that use getNextEntry without any issues. Could this be one of those ‘Strange but true’ Domino issues? :wink:

There is nothing within your loop that conditionally exits the loop??

Subject: RE: ViewEntryCollection loop code failing on server within scheduled agent

hi melissa,

i had intended to post the code that calls the agent to show that there was nothing different as you asked if there was any additional code… my original post contains the relevant code for the agent - the method that gets called is the same

there isn’t anything conditional in the loop that would cause it to exit it, but why would it exit the loop when run on the server and not in any other circumstance…

i’m thinking it is very likely a “strange but true” domino issue - bless it, doesn’t it have a lot of them!? will wait a little longer before i make the change, haven’t yet got access to the logs (server admins in GMT+6) and i’ll see if anyone else replies with similar experiences…

Subject: RE: ViewEntryCollection loop code failing on server within scheduled agent

OK let me know if you find out. Isn’t it strange how often Domino bugs are greeted with “bless…”!

:wink:

Subject: RE: ViewEntryCollection loop code failing on server within scheduled agent

Hi Helen/Melissa,

May not be a “blessed bug”…

If you are updating documents inside the loop, then getNextEntry has problems knowing which is the next entry, So it is always advised to get NextEntry before you do the update, and set viewentry at the end of the loop using current entry.

A Viewentrycollection is a collection of entries in a view sorted order and this will be effected if documents are changed/updated. unlike a document collection which is sorted by note id’s and is not effected by document updates.

One more suggestion, Please try setting view.Autoupdate = false at the start of the loop. This will not update the view while the code is updating the documents i.e. view will remain static during the process. and at the end again set view.autoupdate = true.

Hope this helps in some way…

Best Regards,

Munish Kaushik