Solved

Agent to create documents in another view

Posted on 2006-07-11
33
358 Views
Last Modified: 2013-12-18
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
Comment
Question by:shuboarder
  • 15
  • 13
  • 5
33 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17083372
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17098105
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17098526
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17099494
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
 

Assisted Solution

by:Krisjaniz
Krisjaniz earned 50 total points
ID: 17099552
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17099614
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
 

Expert Comment

by:Krisjaniz
ID: 17099685
That certainly would be even better. I was so terrified by what I saw in Q_21214083.html that I lost all sanity :)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17099707
So easily?? Better have a chat with Dr. Phil...
0
 

Expert Comment

by:Krisjaniz
ID: 17099803
Well my last visit to this site was eight years ago. Nerves are not what they used to be.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17099892
I saw that. Pretty persistent password you have ;)
0
 
LVL 21

Author Comment

by:shuboarder
ID: 17121754
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
 

Expert Comment

by:Krisjaniz
ID: 17121788
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
 

Expert Comment

by:Krisjaniz
ID: 17121795
If you use the first you must remember to set at least the newdoc.Form to form2
0
 
LVL 21

Author Comment

by:shuboarder
ID: 17128580
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17128604
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17129516
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 21

Author Comment

by:shuboarder
ID: 17130644
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
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 450 total points
ID: 17131341
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17131559
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17134236
You also adapted your view? Sorted or categorized, first column repeat_every?
0
 
LVL 21

Author Comment

by:shuboarder
ID: 17136985
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17137421
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17137488
yes... thats the general view...

Repeat Every             Name                   Job

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


etc...
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17137626
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17138182
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17139699
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17144728
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
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 450 total points
ID: 17144771
Oh heck:
     Dim wday As String

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17144774
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17145332
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17145389
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
 
LVL 21

Author Comment

by:shuboarder
ID: 17145595
Thanks a lot! - You've been a great help as always! ;)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17146806
:)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

12 Experts available now in Live!

Get 1:1 Help Now