hii want to write agent that should archive the document in the view that are previous month
agent should run monthly, if today is 1 november and today agent will run at 12:00 am clock: and will archive the document of previousely month. and there is selection formula in the view that will not display the last statsuDoc!=archive
i hope i have explain my self
there is complusory policy to write the agent and but not setting in the administrator side
thanks any help will appericiate
DEVss’’
here is the code
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim udoc As NotesUIDocument
Dim udoc1 As NotesUIDocument
Dim sr As String
Dim dt As NotesDateTime
Dim doc As NotesDocument
Dim doc1 As NotesDocument
Dim collection As NotesDocumentCollection
Dim db As notesdatabase
Dim vw As NotesView
Dim docnext As NotesDocument
Dim mth As Integer
Dim x As Long
Dim modified As NotesDateTime
Dim item As String
Set db= session.GetDatabase("server","Database file") ''initialization of server and database
Set vw= db.GetView("vwEmployeeID")
Set doc = session.DocumentContext
Set doc = vw.GetFirstDocument
''Set dt = New NotesDateTime("Today")
''Set modified= New NotesDateTime("")
''this function will work if the document is previous 1 month
If Year(doc.Created) <= Year(Today) Then
If Month(doc.Created) < Month(Today) Then
Do While Not(doc Is Nothing)
doc.StatusDoc="Archive"
Set docNext =vw.GetNextDocument(doc)
Call doc.Save(False,False)
Set doc = docNext
Loop
End If
End If
You don’t say what’s not working, but your date checking wouldn’t work.
You need to check the year and month slightly differently, something like:
if (year(doc.created)=year(today) and month(doc.created)<month(today)) or year(doc.created)<year(today) then
…
Also, because you’re going through the view and updating a field that affects whether the document will be in the view or not the getnextdocument may fail.
I think all you need to do is put a vw.autoupdate = false before you start the looping, and then reverse it at the end.
If you still have problems post back, but say what’s not working next time.
what actually problem facing is that, when i ran tha agent for the first time it was running nice and was archiving the document, but what happens, for testing purpose i have pasted the document in the test database and retried it by scheduled agent, then since that not archiving the document, since we have condition in the view is StatusDoc!= Archive and was running nicely before, but now no?
and therefore i have make it reguler agent still getting the problem the thing is that we have lots of view that have same criteria
There’s no reason why that wouldn’t work - what is the value of month(doc.created)? Is it definitely less than month(today)?
Did you change the date test line as I mentioned, because the way you had written it anything written last year in november wouldn’t be archived now, as the month wouldn’t be less.
I think you’re running across the problem I mention with the doc that you’ve just changed being removed from the view, then you’re trying to get the next document after the current document, but the current doc’s not in the view any more.
Could you try this with the debugger on, and let me know the exact error.
Have you tried putting the view.autoupdate = false line in?