Improve company productivity with a Business Account.Sign Up

x
?
Solved

Scheduled Agent to create documents via schedule in a view

Posted on 2006-07-20
10
Medium Priority
?
245 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
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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 2000 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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

  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…
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.
Watch the video of Kernel Migrator for SharePoint, which demonstrate the process easily of migration from SharePoint to SharePoint, OneDrive for Business & Google Drive servers, Public Folder to SharePoint, File Server to SharePoint. The tool has va…
If you are looking for an automated tool which can generate reports for Outlook emails and other items from PST file, then you can go for Kernel PST Reporter tool. The reports which are created by this tool are helpful to analyze and understand PST …

607 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