Solved

Scheduled Agent to create documents via schedule in a view

Posted on 2006-07-20
10
232 Views
Last Modified: 2013-12-18
I've just asked a very similar question to this, and am forever grateful to Sjef for helping out with it.
Unfortunately as always I now need to take this a step further...

Here is the situation...

I have an agent that runs daily.
It collects documents from a view and creates new documents depending on the day of the week.
This works by comparing weekday(today) with the value in a combobox on the form

What I need to achieve now is to set this up so that somehow it can create documents spanning multiple weeks.
i.e. at the moment I can only create the same documents every week. I need to be able to specify for example create document every 4 weeks (28 days) on the form.

I'm stuggling with working out how I can set this up.

I'm thinking along the following lines:

Field: Start_LastRun_Date = user specified date
Field: Repeat_Every = user specified period (days)
Field: Collection_Date = computed date (start_date + repeat_every)

The agent which runs daily should collect documents from the view where Collection_Date = Today
It should then create this document through form2. It should also modify the Start_LastRun_Date to = Now
and save the original document. Thus the original document's Collection_Date will recompute to the next period, and the cycle will begin again.

Hope that makes sense?

Points awarded for:

a) verifying this is all possible and will work
b) help creating an agent to do all this!
0
Comment
Question by:shuboarder
  • 5
  • 5
10 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
a) all possible
b) tomorrow? *yawn*

One tiny correction, think about it:
    ... collect documents from the view where Collection_Date >= Today

Last question: are created documents required the day itself? If so, is it possible to create documents ahead of time?
0
 
LVL 21

Author Comment

by:shuboarder
Comment Utility
Sjef, you are a machine!

Tomorrow is grand. Dankzegging

 ... collect documents from the view where Collection_Date >= Today
I'm thinking, but nothing's happening :)
Why would I want to also collect documents with a date beyond today?

The agent will hopefully only need to run once a day
and will only create documents for the current day.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
Why >= Today? Agents might not run. What's worse sometimes: agents might run twice...

The best thing you can do is to implement some sort of activity queue in a view: first column contains date/time the document should be run again, sorted desceding. Your agent can then start at the top, handle those documents that have a rundate<=Today, until the first document is found with a date >Today (or >= Today).

Remember, Today returns the current date with seconds set to 0, so midnight (00:00:00). So if you intend to allow a time, comparing with <= Today effectively means with a date/time of Yesterday.

Does this help already?
0
 
LVL 21

Author Comment

by:shuboarder
Comment Utility
I guess so, because I only want to be comparing the date not the time
so really I think I should be using @date(@today)?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
In the form for the users, where they type the date, they can also type a time. That's where you need to have an Input Translation formula like @Date(rundate).
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 21

Author Comment

by:shuboarder
Comment Utility
something like this....?

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim collection As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim newdoc As NotesDocument
      Dim rdate As String
      
      rdate= Cstr(Date(Today))
      Set db = session.CurrentDatabase
      Set view = db.getview("PPM")
      Set collection = view.GetAllDocumentsByKey(rdate, True)
      Set doc= collection.GetFirstDocument
      
      'Call doc.GetItemValue.next_run_date
      'If rdate = next_run_date
      'Then
      'doc.last_run_date=rdate
      
      While Not(doc Is Nothing)
            Set newdoc = New NotesDocument ( db )
            Call doc.CopyAllItems(newdoc,True)
            Call newdoc.Save( True, False )
            Set doc = collection.GetNextDocument(doc)
      Wend
End Sub
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 500 total points
Comment Utility
More like this

Sub Initialize
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView
     Dim doc As NotesDocument
     Dim odoc As NotesDocument
     Dim newdoc As NotesDocument
     
     Set db = session.CurrentDatabase
    ' assume view PPM: 1st column contains date value, sorted descending
     Set view = db.getview("PPM")
     Set doc= view.GetFirstDocument
     Do Until doc Is Nothing
          If doc.ColumnValues(0)>Now Then Exit Do
          Set newdoc = New NotesDocument ( db )
          Call doc.CopyAllItems(newdoc,True)
          newdoc.Form= "form2"
          Call newdoc.Save(True, False)

' doc should be modified here, so it will move down in the view
' but watch it, this will affect NextDoc, so do that first
          Set odoc= doc
          Set doc = view.GetNextDocument(doc)
          odoc.NextRunDate= Today + doc.Interval(0) ' or so
          Call odoc.Save(True, False)
     Loop
End Sub

This wil even work when you are going to use the time as well in the future.
0
 
LVL 21

Author Comment

by:shuboarder
Comment Utility
Sjef, that's looking great!

Just to confirm, do I want the date decending as in:

Date:

Furthest Away
|
|
V
Soonest

or ascending

Date:

Soonest
|
|
V
Furthest Away

I'm sure you're right, but might need a bit more explanation please
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
In this case, I think I was mistaken, you need Ascending. :$ It'll have to be a view that shows the documents you need to handle at the top of the list.

Apologies. I suppose you wouldn't believe me if I said it was a test...
0
 
LVL 21

Author Comment

by:shuboarder
Comment Utility
No.... lol
but if it was, I did good :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now