First I want to say I am a beginner…
I am working on a script (LotusScript) where I want to create an agent to check the claim forms submitted in the past 24 hours (date Range). If a claim form is found to have no action taken in that 24 hour span, then an email will be sent to a Notes Group with a link to the form(s). I would like this Agent to run during the night and on it’s own. I have been working on this for days now, and I really have nothing that works right. I have very small bits and pieces and that’s it!
I hope that someone is is generous enough to help me with the code (complete code
). While I still have some hair left! I realize that the scope of this is way out of my capibilites and understanding.
Example, I have found a LotusScript that should reference a form and include it a document link in an email. I am getting errors! First error: “To run this Agent you must have at least one document selected”
Here is what I have so far…
Sub Initialize
Dim session As New NotesSession
Dim db As New NotesDatabase("", "PClaims.nsf")
Dim view As NotesView
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim doc As NotesDocument
Set view = db.GetView( "PClaim" )
Set newDoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( newDoc, "Body" )
Set doc = view.GetFirstDocument
While Not ( doc Is Nothing )
Call rtitem.AppendDocLink( doc, db.Title )
Call rtitem.AddTab( 1 )
Call rtitem.AppendText( doc.Subject( 0 ) )
Call rtitem.AddNewLine( 1 )
Set doc = view.GetNextDocument( doc )
Wend
newdoc.Principal ="PClaims"
newDoc.Subject = _
"PClaims Form Needs Your Attention!"
newDoc.SendTo = "Michael@somedomain.org"
Call newDoc.Send( False )
End Sub
Subject: Newbie-LotusScript
Hi,When u r writing a agent first u need to select the target.
In agent properties select None or all documents in the view or all documents in the database etc…
then u have to proceed.
as per ur code instead of hard coding the names use field names. for further guidence see Notes designer help
cheers
RAJ
Subject: RE: LotusScript Include a Doclink
You must create the body with NotesDocument.CreateRichTextItem and then use the NotesRichTextItem classes to put the data in. The way you’ve done it, Body is a text item.
Subject: Newbie-LotusScript
I couple of things ot think about while designing this:
-
How are you determining whether or not a doc has come in in the last 24 hours? I see no code that looks at a creation date or anything. (you may be tempted ot use a view that has some sort of date specific selection criteria using @Today or @Now tossed in there somewhere…don’t)
-
How are you tracking the actions taken, and how are you filtering out those documents that have had actions taken? If you have some sort of status field you can use in your view selection formula that would work well.
You need to answer those questions first before you write the rest of the agent. After that, the rest of the code can vary depending on your answers to 1 and 2.
Subject: Newbie-LotusScript
Why LS? A formula agent could do the job fast and easy.
@If(SubmitDate < @Adjust(@Now;0;0;-24;0;0;0) & ActionTaken != “Yes”;
@MailSend(…);
@Return(“”));
This assumes you set a field ‘ActionTaken’ to ‘Yes’ once action is taken so YMMV.
Also, my @Adjust makes the agent look for ‘anything that’s been sitting around more than 24 hours without action’ so if you want something different, you’ll need to change the forumula and tune in the right range of times.
HTH
Doug
Subject: RE: Newbie-LotusScript
I was told that this was the best (and only way) to do this. The guy that is supposed to be helping me, feels that I should be figuring all this out on my own. That’s fine, but if you do not understand a whole heck of allot about programming then mistakes are numerous. He did give me a book to use as reference. He says “Start on Chapter 29 and you can find out how to program using LS.” I said, “what about the first 28 chapters?” OK sorry for coming across like I’m venting, but I guess the learning curve got me frustrated.
(I had found an example of what you have in the Designer help, the other day, but I did not use it b/c I did not understand it’s function). So I have taken the code and played with it a bit to see what I can make it do.
Down to business…
Temporarily I have set my Agent to trigger on event so I can test it. Later I will set a schedule and have it run during the night. My Target is set to All New & Modified Docs. I have created a view with the following code:
SELECT Form = “P3Claim” & SentEmailNotice = “Yes” & ClaimStatus = “Ready for Submission” & @Now > @Adjust(@Created ; 0 ; 0 ;-24 ; 0; 0 ; 0 );@Return(“”)
I have placed a field (hidden) on my form that is set to “No”
My Agent reads as follows:
Document Selection is set to “P3Claim” which is the alias name of the form.
Initialize is set to:
Sub Initialize
Dim s As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set s=New notessession
Set db=s.currentdatabase
Dim doc As NotesDocument
Set view = db.GetView("emailNotice")
Set newDoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( newDoc, "Body" )
Set doc = view.GetFirstDocument
While Not ( doc Is Nothing )
doc.SentEmailNotice="Yes"
Call doc.Save( True, True )
Call rtitem.AppendDocLink( doc, db.Title )
Call rtitem.AddTab( 1 )
Call rtitem.AppendText( doc.Subject( 0 ) )
Call rtitem.AddNewLine( 1 )
Set doc = view.GetNextDocument( doc )
Wend
newdoc.Principal ="P3Claims"
newDoc.Subject = _
"P3Claims Form Needs Your Attention!"
newDoc.SendTo = "Michael"
Call newDoc.Send( False )
End Sub
I will try to test it this morning!
Subject: RE: Newbie-LotusScript
FYI: Using @Now in a view selection formula is not recommended. As the number of documents in your database grows, it will destroy performance. This is because the value of @Now changes constantly, so the view index will be out of date as soon as it is saved and will need to be rebuilt every time it is accessed.
It would be better to use a view that is sorted by date and use the NotesViewNavigator object to walk through the documents, exiting as soon you get past the time range that you are interested in.
Subject: RE: Newbie-LotusScript
Man! Thanks for all the advice! Makes my life a bit easier now that I can see how this is working and the results I get when the action is run!