An Agent that will create dox and archive old ones

Hi Guys


What I m going to need to at year end is run an agent that will examine the different documents and based on a date and status would archive documents to a archive database.
Part two may be harder

I will need it to create new documents based on the Name field and a formula that wpild look at the number or remaining vacation days. Any days from 1 to 5 would be brought as CarryOver days any thing over 5 would become 5 and then refresh the document.

Is this a monster or easily done

I need this for year ends


James
adspmoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HemanthaKumarCommented:
I don't think I can give full working code here.. but here is the sample that you can extend

DateStr = "01/01/2003"     ' You can receive this string using Inputbox method so no hardcode is necessary
Dim session as New NotesSession
dim db as NotesDatabase
dim col as NotesDocumentCollection
dim doc as notesdocument, vac as notesdocument
dim cutoff as New NotesDatetime( DateStr )

set db = session.CurrentDatabase
searchstr = {FORM = "Vacation" & ArchiveBit = 0 | @isUnavailable(ArchiveBit)}
set col = db.Search( searchstr, cutoff, 0)
set doc = col.GetFirstDocument
While not doc is nothing
' Set Archive flag so that the scheduled or someother agent can copy it to another db and delete it
if Datevalue(cstr(doc.Created)) = DateValue(DateStr) then ' Archive Flag
   doc.ArchiveBit = 1      ' Whatever archive status that you are using
   doc.Save true, false
end if
' Now new vacation document..
set vac = db.CreateDocument   ' Create vacation doc for next yr
vac.Form = "Vacation"
if doc.VacationRemaining(0) > 5 then           ' I believe it is a number data type field
   vac.CarriedOver = 5
else
   vac.CarriedOver = doc.VacationRemaining(0)
end if
vac.ComputeWithForm true, false
vac.save true, false
set doc = col.GetNextDocument(doc)

Wend

~Hemanth
0
adspmoAuthor Commented:
Thanx I will start playing with it
0
adspmoAuthor Commented:
Here is what I have come up with so far

Sub Initialize
      DateStr = "01/01/2003"     ' You can receive this string using Inputbox method so no hardcode is necessary
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim col As NotesDocumentCollection
      Dim doc As notesdocument, vac As notesdocument
      Dim cutoff As New NotesDatetime( DateStr )
      
      Set db = session.CurrentDatabase
      searchstr = {FORM = "AvailHolidays" & ArchiveBit = 0 | @isUnavailable(ArchiveBit)}
      Set col = db.Search( searchstr, cutoff, 0)
      Set doc = col.GetFirstDocument
      While Not doc Is Nothing
' Set Archive flag so that the scheduled or someother agent can copy it to another db and delete it
            If Datevalue(Cstr(doc.Created)) = Datevalue(DateStr) Then ' Archive Flag
                  doc.ArchiveBit = 1      ' Whatever archive status that you are using
                  doc.Save True, False
            End If
' Now new vacation document..
            Set vac = db.CreateDocument   ' Create vacation doc for next yr
            vac.Form = "AvailHolidays"
            If doc.AllowanceAH_2(0) > 5 Then           ' I believe it is a number data type field
                  vac.CarriedOverAH = 5
            Else
                  vac.CarriedOverAH = doc.AllowanceAH_2(0)
            End If
            vac.ComputeWithForm True, False
            vac.save True, False
            Set doc = col.GetNextDocument(doc)
      Wend
End Sub


I am getting a typemismatch on this line

I have played around with it ,still getting the error

James
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

HemanthaKumarCommented:
Which line ?
0
adspmoAuthor Commented:
Duh


Cut no paste!!!

If doc.AllowanceAH_2(0) > 5 Then          
0
HemanthaKumarCommented:
Probably it is a text field

Convert it to number before comparing

If cint(doc.AllowanceAH_2(0)) > 5 Then          
0
adspmoAuthor Commented:
Same error, All the fields that are recording this info are number type
0
HemanthaKumarCommented:
Can you debug and see the value in the debugger has legal value ?
0
adspmoAuthor Commented:
Doc seems to be picking the wrong form
0
HemanthaKumarCommented:
Is the searchstr formula

{FORM = "AvailHolidays" & ArchiveBit = 0 | @isUnavailable(ArchiveBit)}


is correct ?

0
adspmoAuthor Commented:
As far as the form name goes YES

The ArchiveBit doesn't exist

That is a virtual Field is it not

0
HemanthaKumarCommented:
Yes it is a virtual field.

Modify the search string like this (notice brackets)
{FORM = "AvailHolidays" & (ArchiveBit = 0 | @isUnavailable(ArchiveBit))}


Then how did you conclude that doc is picking different form ?
0
adspmoAuthor Commented:
I looked at Doc in the Debugger variables under Items and the field names were from a different form

0
adspmoAuthor Commented:
Hi

It gets to
While doc is Nothing and then jumps to End Sub

Sub Initialize
      DateStr = "12/12/2003"     ' You can receive this string using Inputbox method so no hardcode is necessary
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim col As NotesDocumentCollection
      Dim doc As notesdocument, vac As notesdocument
      Dim cutoff As New NotesDatetime( DateStr )
      
      Set db = session.CurrentDatabase
      searchstr = {FORM = "AvailHolidays" & (ArchiveBit = 0 | @isUnavailable(ArchiveBit))}
      
      
      Set col = db.Search( searchstr, cutoff, 0)
      Set doc = col.GetFirstDocument
      While Not doc Is Nothing
' Set Archive flag so that the scheduled or someother agent can copy it to another db and delete it
            If Datevalue(Cstr(doc.Created)) < Datevalue(DateStr) Then ' Archive Flag
                  doc.ArchiveBit = 1      ' Whatever archive status that you are using
                  doc.Save True, False
            End If
' Now new vacation document..
            Set vac = db.CreateDocument   ' Create vacation doc for next yr
            vac.Form = "AvailHolidays"
            If Cint(doc.AllowanceAH_2(0)) > 5 Then          
                  
         ' I believe it is a number data type field
                  vac.CarriedOverAH = 5
            Else
                  vac.CarriedOverAH = doc.AllowanceAH_2(0)
            End If
            vac.ComputeWithForm True, False
            vac.save True, False
            Set doc = col.GetNextDocument(doc)
      Wend
End Sub

0
HemanthaKumarCommented:
It means that collection object din't return anything..Copy the formula from SearchStr variable and paste it into a new empty view and see if it fetches any documents.. If so then formula is wrong.

0
adspmoAuthor Commented:
I checke col in the debugger and the count was 0
So you are right the collection is returning nothing
0
HemanthaKumarCommented:
Ok then change the search formula to this

{FORM = "AvailHolidays" & @isUnavailable(ArchiveBit)}

0
adspmoAuthor Commented:
Sorry no go

Just to make sure I am in the right place

I have this in a agent
I am running it against documents created with th AvailHolidays form
The create date is varied

The colection is still empty
0
qwaleteeCommented:
Create a view with the selection formula you want (the selection formula is the same as what you have in SearchStr).  Play with it until you get the view to show the expected documents.  Then use that formula.

If it is returning absolutely nothing, then start with only one part, e.g., SELECT Form = "AvailHolidays" - and make sure some docs are returnd.  then, piece by piece, make it more complex and more/less restrictive.  When you are done, place the final selection formula back in the agent.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HemanthaKumarCommented:
The agent should be set to run once @commands
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.