On Error Goto err_handler
If PNAB.IsOpen Then
Print( "Sub DeleteDocsFromPNAB is running and " & PNAB.Title & " is open." )
Else
Print( "Unable to open PNAB..." )
Exit Sub
End If
Dim junkDocs As NotesDocumentCollection
Dim PNABview As NotesView
Dim PNABdoc As NotesDocument
Dim cnt, x As Integer
Set junkDocs = PNAB.Search ( "" ,Nothing ,0)
Set PNABview = PNAB.GetView( "People" )
If Not (PNABView Is Nothing) Then
Set PNABdoc = PNABview.GetFirstDocument
If Not (PNABdoc Is Nothing) Then
cnt = 0
x = 0
Print "Count is " & cnt & ", and x is " & x &"."
While Not (PNABdoc Is Nothing)
If (PNABdoc.HasItem ( "SynchSource" )) Then 'Field "SynchSource" was added to any document copied from ONAB to PNAB.
Call junkDocs.AddDocument (PNABdoc)
cnt = cnt+1
End If
Set PNABdoc = PNABview.GetNextDocument (PNABdoc)
x = x + 1
Wend
End If
End If
If cnt > 0 Then
Print "Count is " & cnt & ", and x is " & x &"."
Stop
Call junkDocs.RemoveAll(True)
Print "Deleting " & cnt & " docs from your address book."
End If
err_handler:
If Err <> 0 Then
Msgbox Err
Call logErrors(Err,Error$, "Agent: Synch Personal Contact List; Sub: DeleteDocsFromPNAB")
End If
End Sub
The call to junkDocs.RemoveAll (True) throws a 4241 (lsERR_NOTES_CANTREMOVE) error.
All the avriable values look ok in debugger. I’m at wits end.
What a pleasant surprise. I just finished your informative article “Debugging LotusScript.” Thank you for that.
The error text is, “Cannot remove NotesDocument when instantiated by NotesUIDocument”
The Environtment:
This code runs as an agent in an “Outside NAB” directory. It is part of a synchronization routine that synchs selected ONAB docs with the user’s Personal NAB, then pushes those out to Lotus Notes Traveler address book, through the native Notes synch to mail file in R8. We have a folder in ONAB that is specific to the user. He populates the folder with his selected contacts, then “Synchs” which pushes those docs to the PNAB. Other routines keep docs “synched” on a field level.
To encourage users to be frugal with their contact numbers (in recognition of the limitations of the mobile LNT device memory), we want to have user remove un-needed docs from the ONAB folder, and delete those same docs in PNAB.
If the PNAB is open in the user’s WS when this runs, it throws the error. If the user’s PNAB is not open in the UI, it runs fine. Trouble is, the user has to open the PNAB to check the results, and we’d like to keep this open for him.
After reading your article, I checked the entire agent code for references to the UI and found one, which I removed with no improvement.
Your thoughts are most appreciated. And, thanks again for your work.
Subject: “Cannot remove NotesDocument when instantiated by NotesUIDocument”
In other words, it doesn’t want to delete a document in the back end when you obtained the NotesDocument handle from the front end – a document you have open. Since you say you eliminated all the UI stuff from your code, I assume it’s that you’re running on a NotesDocument from the UnprocessedDocuments collection, but it’s the document you have open. So if you get this error, it would seem that you should trap it and try deleting the document a different way, via NotesUIWorkspace.CurrentDocument.DeleteDocument. Or, if it needs to be a hard delete, respond to the error by closing the document (uidoc.close), and then delete the NotesDocument from memory (Delete statement), re-get the document from the back end using the noteID which you have previously stored, and then delete it.
If I’ve understood the problem correctly and this approach works for you, please reply, because in that case I’d like to technote it. Thanks.
We have the custom (ONAB) application that contains the agent open to a view (no docs are open.) We have the personal address book open to a view “People” the standard R8 design. These are both on the Notes client, and both apps are local.
When the agent runs, no docs are open, and we have no (zero) ui object references anywhere in the agent events, subs or functions code.
I worked on this quite a bit last month and found the error was not always reproducible. When it did occur, either changing views in the personal address book, or closing the personal address book solved the problem.
So, I trapped the error to a) send me a message when it occurs, and b) to prompt the user to close his personal address book then re-run the agent.
I’ve since deployed the application to production and have not seen any errors so perhaps it was something unique to my environment.
If it pops up again, I’ll try to narrow it down more for you.
Well I that sure hadn’t occurred to me. I’ve not heard of any complaints from the users or the error handler. When I visit that application in the future, I’ll try the preview pane idea.