I would like to create an agent that will scan a particular view in a database that will either have a status of “outstanding” or “completed”. This agent will run every hour and send an email to users of this database saying either if it complete or outstanding. Is this possible? And at the last hour, it will send an email stating that all requests are complete.
Any help would be greatly appreciated. New to using lotus script. I was also wondering if it would be better using the formula language.
Why lotusscript?Message := “Your text here that is enter stuff you enter or " + FieldValue + " so you can specify some document identifier and status”;
@MailSend(fill in the parameters);
Not sure what you mean by ‘at the last hour’ so I can’t provide specific guidance here.
Note - if there are a lot of docs in this view and users will receive multiple emails, I’d suggest you check out the NotesNewsletter method so you only send one email to each user.
Yeah, Im not sure if I can use formula language or script. But Here’s the scenario:
I have created an agent that will run every hour from 10am-2pm during week days.
What the agent will do is, scan the view and if it has a status of “Outstanding”, it will send an email to a group (in my code, i use myself). If there is no status of outstanding, it
will not send an email out. It should only look for “Outstanding” and then send an email.
I was wondering if you could take a look at my code. Also, if this should be done using formula language instead.
Any help would be greatly appreciated. Thanks.
Here’s the code:
Sub Initialize
Dim s As notessession
Dim db As notesdatabase
Dim view As notesview
Dim ventry As notesviewentry
Dim doc As notesDocument
Dim nextDoc As NotesDocument
Dim mailDoc As notesDocument
Dim rtitem As notesRichTextItem
Dim richStyle As NotesRichTextStyle
Dim fieldName As String
Dim tmpSubject As String
Set s=New notessession
Set db=s.currentdatabase
Set view = db.GetView("OR")
Set mailDoc = New NotesDocument(db)
Set rtitem = mailDoc.CreateRichTextItem("Body")
Set richStyle = session.CreateRichTextStyle
mailDoc.Form = "Memo"
mailDoc.SendTo = "Jerica Santos"
mailDoc.From = "Database Status"
'mailDoc.CopyTo = ""
tmpSubject = "There is a " + doc.status(0) + " request for "
For i = 1 To 20
fieldName = "ccid" + i
If uidoc.FieldGetText(fieldName) >< "" Then
tmpSubject = tmpSubject + uidoc.FieldGetText(fieldName) +
" "
End If
Next
mailDoc.Subject = tmpSubject
Call rtitem.AppendText("A ")
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.AppendText(doc.type(0))
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.AppendText(" Please review outstanding request. ")
Call rtitem.AppendDocLink(doc, db.Title)
Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
If doc.status(0) = "Outstanding" Then
Call mailDoc.Send(True, doc.SendTo = "Jerica Santos")
End If
Set nextDoc = view.GetNextDocument(doc)
Set doc = nextDoc
Wend
'refresh backend view
Call view.refresh()
'update the front end view
Its possible thru script only. Please create a view and first column should be categorized with the status.
Using the GetallDocumentsByKey method in your scheduled agent collect all the documents into a collection object. By taking each document into account you can send the email and you can set the new status also. Or You can use DBSearch also.
I tried to test the agent and it said that the agent ran but I did not receive an email. I disabled the agent (does that matter when testing?) I also created another view called “Status” that will have the first column that will have the status of outstanding or completed.
here’s my revised code:
Dim s As notessession
Dim db As notesdatabase
Dim view As notesview
Dim ventry As notesviewentry
Dim doc As notesDocument
Dim DocColl As NotesDocumentCollection
Dim DocA As NotesDocument
Dim nextDoc As notesDocument
Dim mailDoc As notesDocument
Dim rtitem As notesRichTextItem
Dim richStyle As NotesRichTextStyle
Dim fieldName As String
Dim tmpSubject As String
Set s=New notessession
Set db=s.currentdatabase
Set view = db.GetView("(Status)")
Set DocColl=view.getalldocumentsbykey("outstanding", True)
Set DocA=DocColl.GetfirstDocument
Set mailDoc = New NotesDocument(db)
Set rtitem = mailDoc.CreateRichTextItem("Body")
Set richStyle = session.CreateRichTextStyle
mailDoc.Form = "Memo"
mailDoc.From = "Project Delivery DB"
'mailDoc.CopyTo = "Jerica Santos"
tmpSubject = "There is an " + doc.esstatus(0) + "Status In the Project Delivery DB. pls action immediately"
mailDoc.Subject = tmpSubject
Call rtitem.AppendText("A ")
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.AppendText(doc.type(0))
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.AppendText("Please review outstanding request. ")
Call rtitem.AppendDocLink(doc, db.Title)
Call mailDoc.Send(True, "Jerica Santos")
Set nextDoc = view.GetNextDocument(doc)
Set doc = nextDoc
'refresh backend view
Call view.refresh()
Sorry for the delay responding…also sorry but I don’t have time to debug your code (turn on the debugger and step through it to see what it’s doing and where it’s failing).
Also - you CAN do this via @Functions.
@If( = “Outstanding”;
@MailSend(Fill_In_The_Stuff_Here);
@Return(“”));
Set it to run on all docs in the db. Unless you have a gazillion docs, it won’t hurt.
LS is more elegant and should allow you to generate a doc collection that is only those docs that need emails, but Functions DO work (and take way less time to write)!
First of all, I would like to say thank you for providing me with feedback.
Second of all, I thought this was a forum for new and existing users of lotus notes. I figured I would display my code and maybe it will explain further on the expectations i intend to portray. I had no intention for you to debug my code. Yes, I have time to debug my code but since i am new to lotus script I figured i can get assistance from this forum as the debugger does not work when your using an agent. Also, I did not know that you were the only one assigned to answering my original question. Anyway, Again, thanks for your feedback its been appreciated.
You’re right, this is a place for just what you describe and normally I’m more than happy to debug code, just not right now (or then rather) as I was in the middle of some stuff that was going to consume my time. I was NOT trying to suggest you shouldn’t post code so my apologies for the mis-understanding; certainly not my intent. There are days I really hate text only interactions…
You can use the debugger when running agents (LS agents anyway). For Function agents, use @Prompts to stop the code and display your intermediate values so you can verify what you think is happening is actually happening. If it’s a scheduled agent, you can either make it a ‘real time’ agent and step through the code or use Print commands to insert debug information into Log.nsf.
When you post code, it is incredibly helpful if you have run the debugger so you can add comments about what it’s telling you at the point the code fails - that just makes it easier for us to help you.
Again, sorry for the confusion.
Doug
ps - when I get snippy, I get REAL snippy And I try not to get snippy since this forum has been my home for Notes stuff for a bucha years and it’s not good to nuke the neighborhood…
No worries. I was kind of frustrated myself. I actually have to correct what I had said about the debugger not working in agents. I figured it out! and when I ran the debugger, I seen the problem. But everything is working now. Thanks for your assistance though. Bits of information here and there are the pieces to a confusing puzzle. Again, thanks!
Glad to hear you figured out the debugger and got the code working. Just to close out the thread, it’s helpful if you post what fixed the problem so the next person who has a similar problem can see how it was handled.