Solved

An Agent that will create dox and archive old ones

Posted on 2003-12-09
20
312 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:adspmo
  • 10
  • 9
20 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9907430
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
 

Author Comment

by:adspmo
ID: 9907874
Thanx I will start playing with it
0
 

Author Comment

by:adspmo
ID: 9957602
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9958207
Which line ?
0
 

Author Comment

by:adspmo
ID: 9958266
Duh


Cut no paste!!!

If doc.AllowanceAH_2(0) > 5 Then          
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9958300
Probably it is a text field

Convert it to number before comparing

If cint(doc.AllowanceAH_2(0)) > 5 Then          
0
 

Author Comment

by:adspmo
ID: 9958431
Same error, All the fields that are recording this info are number type
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9958678
Can you debug and see the value in the debugger has legal value ?
0
 

Author Comment

by:adspmo
ID: 9958885
Doc seems to be picking the wrong form
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9959528
Is the searchstr formula

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


is correct ?

0
 

Author Comment

by:adspmo
ID: 9959744
As far as the form name goes YES

The ArchiveBit doesn't exist

That is a virtual Field is it not

0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9960209
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
 

Author Comment

by:adspmo
ID: 9965349
I looked at Doc in the Debugger variables under Items and the field names were from a different form

0
 

Author Comment

by:adspmo
ID: 9965510
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
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9966109
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
 

Author Comment

by:adspmo
ID: 9966581
I checke col in the debugger and the count was 0
So you are right the collection is returning nothing
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9966680
Ok then change the search formula to this

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

0
 

Author Comment

by:adspmo
ID: 9966845
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
 
LVL 31

Accepted Solution

by:
qwaletee earned 500 total points
ID: 9970458
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
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9972952
The agent should be set to run once @commands
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question