I have an embedded view with checkboxes that I made myself in the view. On the form I have a field with the same name as the checkboxes. The value of the checkboxes are “DocumentUniqueID”. But when I use this code in a agent, which I call from a button, I can se that the field on the form gets “DocumentUniqueID” from the documents I choose in the view. But the choosen document are still there. This is a webapplication. Here is my agent code:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim context As NotesDocument
Dim doc As NotesDocument
Dim item As NotesItem
Dim value As String
Dim Test As String
Dim a As String
Set db = session.CurrentDatabase
Set context = session.DocumentContext
Set item = context.GetFirstItem("DeleteDocs")
Counter = 0
Forall v In item.values
If Counter <> "0" Then
Set doc = db.GetDocumentByUNID(v)
Call doc.Remove( True )
End If
Counter = Counter + 1
End Forall
Print "<script>"
Print "history.go(-1);"
Print "</script>"
If I print a javascript alert with all values (DocumentUniqueID, Username, Form, and so on), it looks alright.
Because it prints out the values you use to the Domino server console, which would indicate the progress and helps you out to find what exactly went wrong.
–Phani
PS - There are various ways to debug a web agent (like - on error statement, agent log, print statements etc) which I forgot to mention in my earlier post.
True, but for on the fly debugging, printing to the browser page is so much more convenient. As a rule, instead of using direct Print statements, I would recommend calling a custom function, eg. “DebugPrint( debugLine As String )”, with a single line Print debugLine this line can then be remm’d/unremm’d when you need all debugging off/on.
D’oh! You’re right. I’m glad it’s almost weekend, i obviously can use some rest.
My guess is that the 1st value of the item does not contain a document id. (since you don’t want the remove action to be performed if counter is 0). If this is so, the agent will generate an error when the counter is 0. Because the statement returns true, the agent will try to get a document by a UNID that does not exists.
Hi Henrik,I faced the same issue in my application. I made a work around for this issue by placing some flag variable DELETEFLAG and set the value as “Y” when the deletion is required in the document and include the selection criteria of the view displayed as dELETEFLAG!=“Y”. Automatically the document is removed from the view.
Run some scheduled agent to remove all the documnets with the deleteflag as Y. Hope this may help you.
This is what I did too, 3 years back when developing a web application. Help file clearly says that “You cannot use the remove method on a Document object returned by the DocumentContext property.”
To make testing easier here, put in an error trap and print out code to throw a js alert with the error number, message, and line. Alternatively, you can temporarily set this up to run from the client (hardcode the UNIDS found in the field into an array) and step through it in the debugger. For Best Practices, Use Option Explicit and declare all of your variables.
Also, I don’t see why this wouldn’t work. You should not need a counter here. Loop through the field using forall and then get a handle to the document using the unid you obtain from the field. There is no need to tally the number of passes.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim context As NotesDocument
Dim doc As NotesDocument
’ Dim item As NotesItem
Dim value As String
Dim Test As String
Dim a As String
Set db = session.CurrentDatabase
’ Set context = session.DocumentContext
’ Set item = context.GetFirstItem(“DeleteDocs”)
Forall v In item
Set doc = db.GetDocumentByUNID(v)
Call doc.Remove( True )
End Forall
Print "<script>"
Print "history.go(-1);"
Print "</script>"