Solved

Scheduled Agent to create documents via schedule in a view

Posted on 2006-07-20
10
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17150392
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
ID: 17150512
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
ID: 17151974
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
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 21

Author Comment

by:shuboarder
ID: 17152346
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
ID: 17152691
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17152817
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
ID: 17152876
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
ID: 17153304
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
ID: 17153377
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
ID: 17154365
No.... lol
but if it was, I did good :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lotus Notes Mail Database issues 2 1,003
IBM Enterprise Integrator - ZID File 1 181
Incorrect reply-to address Lotus 2 47
Lotus Domino server 9 7 91
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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