Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

Agent to create documents in another view

Hi,

Here is my problem...

I have 2 views lets call them view1 and view2
view1 contains a list of jobs to be completed on specific days of the week
view2 contains the current list of jobs that need completing.

What I need is a way of automatically creating the jobs in view2 via an agent depending on the day of the week.
So on Monday, the agent runs and creates new documents in view2 for all the jobs in view1 where field Repeat_Day = Monday

Similar to this question:

http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_21214083.html

This is fairly urgent, so any help is greatly appreciated!
0
shuboarder
Asked:
shuboarder
  • 15
  • 13
  • 5
3 Solutions
 
Sjef BosmanGroupware ConsultantCommented:
Documents are not "created" in a view, they are shown by a view. The question is therefore (if I translated it correctly):
- you want an agent to produce documents
- the agent runs daily
- the agent generates documents that should be selected by the select-formula of a view

1) Correct?
2) What documents need to be created? And how?
3) What's your code attempt?
0
 
shuboarderAuthor Commented:
1) - I know documents are not created in a view but I was trying to make it sound easier as I thought most people would understand what I meant.

2) - I want to create documents via an agent.
The agent should run on documents displayed by view1 created through form1
It should create the same documents through a second form (form2) that will displayed by view2
The agent should only create documents through form2 for the current day of the week on which it runs

So as an example when the agent runs on Tuesday,
it will run on documents displayed through view1 (created through form1)
it will find all the documents where field repeat_day = "Tuesday" and create these documents through form2 to be displayed by view2

3) My code attempt was based around the accepted answer in: Q_21214083.html and also the author's closing comment.
0
 
Sjef BosmanGroupware ConsultantCommented:
Oh goodness, that last bit of code in that question seems rather poor quality to me. You must be able to do that better, I suppose.

What you need is something along the following pseudo-code:

    open view1
    for all documents in view1 do
        if document is repeated with "today" then
            create new document2
        fi
    od

Correct?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
shuboarderAuthor Commented:
Yes,

thats what I'm after! - I agree the author's last posting seems very long winded, but if it works for him that's great.
Now as you know Sjef, my lotus script is poor at best, but here is basically what I'm trying to achieve....

Sub Initialize

Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim newdoc As NotesDocument
Dim col As NotesDocumentCollection

Set db = session.currentdatabase
Set view = db.getview("view1")
set col = view.UnprocessedDocuments
set doc = col.GetFirstDocument

do while doc is nothing

' if field: repeat_every = @today then create this document as new document through form2 else do doc.close

doc.Save false, false
set doc = col.GetNextDocument(doc)
wend

End sub
0
 
KrisjanizCommented:
I would probably do something like this:

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim collection As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim newdoc As NotesDocument
      Dim dateTime As New NotesDateTime(_
      Cstr(Datenumber(2000, 5, 1)))
      searchFormula$ = {Form = "form1" & RepeatDay ="} & Weekday(Today()) & {"}
      Set db = session.CurrentDatabase
      Set collection = db.Search(searchFormula$, dateTime,0)
      Set doc = collection.GetFirstDocument()
      While Not(doc Is Nothing)
            Set newdoc = New NotesDocument ( db )
            newdoc.Form="form2"
            ...
            Call newdoc.Save( True, False )
            Set doc = collection.GetNextDocument(doc)
      Wend
End Sub
0
 
Sjef BosmanGroupware ConsultantCommented:
That would probably be not too bad ;)

If it is possible to avoid the db.Search, you should try that. It will go through the whole database, sequentially. Now, in this case, there is a view with only a few (?) documents that can be scanned. Maybe it's even possible to have a (hidden) view with in the first column the Weekday(repeat_day), so you can get all documents wit view.GetAllDocumentsByKey(weekday) ?
0
 
KrisjanizCommented:
That certainly would be even better. I was so terrified by what I saw in Q_21214083.html that I lost all sanity :)
0
 
Sjef BosmanGroupware ConsultantCommented:
So easily?? Better have a chat with Dr. Phil...
0
 
KrisjanizCommented:
Well my last visit to this site was eight years ago. Nerves are not what they used to be.
0
 
Sjef BosmanGroupware ConsultantCommented:
I saw that. Pretty persistent password you have ;)
0
 
shuboarderAuthor Commented:
Ok, I'm gonna need a bit more help obviously....
what are we supposed to be doing in the ....? Setting the individual field values?

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
     
     Set db = session.CurrentDatabase
     Set view = db.getview("view1")
     Set doc = view.GetAllDocumentsByKey(weekday)
     While Not(doc Is Nothing)
          Set newdoc = New NotesDocument ( db )
          newdoc.Form="form2"
          ...
          Call newdoc.Save( True, False )
          Set doc = collection.GetNextDocument(doc)
     Wend
End Sub
0
 
KrisjanizCommented:
Yes, you can either use
    Call doc.CopyAllItems(newdoc,True)
to copy all fields
or copy only certain fields using the CopyItem method
or just assign some fields some values

depending on your specific needs
0
 
KrisjanizCommented:
If you use the first you must remember to set at least the newdoc.Form to form2
0
 
shuboarderAuthor Commented:
How is this looking then...?

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
     
     Set db = session.CurrentDatabase
     Set view = db.getview("view1")
     Set doc = view.GetAllDocumentsByKey(weekday)
     While Not(doc Is Nothing)
          Set newdoc = New NotesDocument ( db )
          newdoc.Form="form2"
          Call doc.CopyAllItems(newdoc,True)
          Call newdoc.Save( True, False )
          Set doc = collection.GetNextDocument(doc)
     Wend
End Sub
0
 
Sjef BosmanGroupware ConsultantCommented:
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
     
     Set db = session.CurrentDatabase
     Set view = db.getview("view1")
'     Set doc = view.GetAllDocumentsByKey(weekday)
     Set collection = view.GetAllDocumentsByKey(weekday)
     Set doc= collection.GetFirstDocument
     While Not(doc Is Nothing)
          Set newdoc = New NotesDocument ( db )
'          newdoc.Form="form2"
          Call doc.CopyAllItems(newdoc,True)
          newdoc.Form="form2"
          Call newdoc.Save( True, False )
          Set doc = collection.GetNextDocument(doc)
     Wend
End Sub

Where's weekday coming from?
0
 
shuboarderAuthor Commented:
weekday should be my field value repeat_day I believe,

but there's no part of the code that says to match this up with today's weekday value.
0
 
shuboarderAuthor Commented:
Ok, I'm really struggling with this... I'm thinking there may be a better way of doing things.

If I make my repeat_every field a number field

then if a user put for example "30" in this field, the document should be created every 30 days through form2.

somehow I need to count down from 30 on the document... more agents??! arrrrghhhh

I should then create a view that displays documents with selection formula field repeat_every = "1"

Every day an agent should run on this view and create documents through form2

Please, I really do need help with this!


 
0
 
Sjef BosmanGroupware ConsultantCommented:
Is weekday the current day of the week, the day the agent runs? Doing it by weekdays is no problem. It is a lot easier if you don't use names for days of the week, but the values Weekday(Today) returns: 1 to 7 (Sunday=1, Saturday=7). That would make testing a lot easier.

To specify when an agent should run, make CheckBox-field with 7 options:
    Sunday | 1
    Monday| 2
etc., so the field will contain a string value "1" to "7". This value can easily be converted to an integer.

So, in your view you categorize documents by their weekday-number.

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 wday As Integer
 
     wday= Cstr(Weekday(Today))
     Set db = session.CurrentDatabase
     Set view = db.getview("view1")
'     Set doc = view.GetAllDocumentsByKey(wday)
     Set collection = view.GetAllDocumentsByKey(wday)
     Set doc= collection.GetFirstDocument
     While Not(doc Is Nothing)
          Set newdoc = New NotesDocument ( db )
'          newdoc.Form="form2"
          Call doc.CopyAllItems(newdoc,True)
          newdoc.Form="form2"
          Call newdoc.Save( True, False )
          Set doc = collection.GetNextDocument(doc)
     Wend
End Sub

Fiwst have a wook, then pwease twy again.
0
 
shuboarderAuthor Commented:
If weekday = 3 = Tuesday
then on a Tuesday the agent (which will run daily) should create documents through form2 for all docs displayed by view1 where field repeat_every = 3

Do I need to rename my field? I can't see where this is queried in the code.

I tried what you suggested above, and although I don't get any errors (using option declare)
I get no documents created...
0
 
Sjef BosmanGroupware ConsultantCommented:
You also adapted your view? Sorted or categorized, first column repeat_every?
0
 
shuboarderAuthor Commented:
View is sorted and categorised on the first column which is field repeat_every

Should I be using any document selection in the agent?

I tried with select all docs by form1 and the agent found the 7 documents that the view displays:

Started running agent 'PPM' on 19/07/2006 10:45:41
Running on all documents in database: 3615 total
Found 7 document(s) that match search criteria
Ran LotusScript code
Done running agent 'PPM' on 19/07/2006 10:45:49

I also tried without document selection - this was faster, but appeared to select everything in the database

Started running agent 'PPM' on 19/07/2006 10:54:58
Running on all documents in database: 3615 total
Found 3615 document(s) that match search criteria
Ran LotusScript code
Done running agent 'PPM' on 19/07/2006 10:54:58

There is nothing being created in the database - I have checked with a view with select @all and sorted by date created.
0
 
Sjef BosmanGroupware ConsultantCommented:
shuboarder,
> Should I be using any document selection in the agent?
No. The agent uses a view, so applying a document selection is useless.

What does the view show?

> 1
    hjfjhfjhf jhfjh
    jhf jhfjhfjfjh
> 2
    jhf djhfjhgf

etc?
0
 
shuboarderAuthor Commented:
yes... thats the general view...

Repeat Every             Name                   Job

>1
                               Bob                      Builder
>2
                               Pat                       Postman
>3            
                               Budgie                  Helicopter


etc...
0
 
Sjef BosmanGroupware ConsultantCommented:
Did you try to run the agent manually, after having switched on the LotusScript Debugger? You can see all variables and objects and inspect them in detail. Set a breakpoint after the line where the collection is fetched, so you can see the number of documents in the collection.
0
 
shuboarderAuthor Commented:
yes it was manually. Just tried the LotusScript debugger.
I don't think it is collecting the documents:

ALLENTRIES [7,""]
COUNT 7
QUERY ""

COLLECTION [0, FALSE, ""]
COUNT 0
ISSORTED FALSE
QUERY ""
0
 
Sjef BosmanGroupware ConsultantCommented:
Not good. Can you put your latest code attempt in here?

Things to verify:
- you open the correct view in your code (no 2 views with the same name)
- the first column is sorted or categorized
- the first column's value is a string
- there are documents in that view for category 4 (Wednesday)
0
 
shuboarderAuthor Commented:
Sjef, thanks for sticking with me on this one.

Verifying....

- Correct view is opened, and there are not 2 views with the same name or alias
- First column is sorted and categorised
- First column is a string
- There is a document in the view for each category

Latest Code attempt:

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 wday As Integer
      
      wday= Cstr(Weekday(Today))
      Set db = session.CurrentDatabase
      Set view = db.getview("PPM")
      Set collection = view.GetAllDocumentsByKey(wday)
      Set doc= collection.GetFirstDocument
      While Not(doc Is Nothing)
            Set newdoc = New NotesDocument ( db )
            Call doc.CopyAllItems(newdoc,True)
            newdoc.Form="GC"
            Call newdoc.Save( True, False )
            Set doc = collection.GetNextDocument(doc)
      Wend
End Sub
0
 
Sjef BosmanGroupware ConsultantCommented:
Oh heck:
     Dim wday As String

0
 
Sjef BosmanGroupware ConsultantCommented:
And I'd advise you to change this line as well
    Set collection = view.GetAllDocumentsByKey(wday, True)
to get an exact match. It won't matter in this case, but it might prevent later trouble.  
0
 
shuboarderAuthor Commented:
Thanks Sjef - Documents are now being created!!

Finally (I promise) If I want to add information to additional fields on the new document,
I can do it like this (after the newdoc.Form="GC" line):

newdoc.fieldname="value"

Anything wrong with this method?



0
 
Sjef BosmanGroupware ConsultantCommented:
Nothing whatsoever.

Only if fieldname contains special characters, you have to use
    newdoc.ReplaceItemValue("fieldname", value)

although there's even a bypass for that (but I forgot how  :$ )
0
 
shuboarderAuthor Commented:
Thanks a lot! - You've been a great help as always! ;)
0
 
Sjef BosmanGroupware ConsultantCommented:
:)
0
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

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.

  • 15
  • 13
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now