Automatic Notification

I have a database that has forms containing an expiration date field. I need to create a notification agent to check the entire database on a daily basis. When the expiration date is 30 days away, I would like to send out an email to the author of the document notifying them that their form will expire. I need to include a standard message in the body as well as a copy of the entire form. The authors do not have access directly to the database, so a doclink will not work. The forms also have a hardcoded SendTo value that can be changed, but should not be saved.

How can I do something like this below but include the entire document in the body of the email?

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set collection = db.AllDocuments

Set doc = collection.GetFirstDocument

Set doc2 = New NotesDocument(db)

Set item = doc.GetFirstItem("Subject")

Call item.CopyItemToDocument(doc2, "Subject")

Set item = doc.GetFirstItem("Body")

Call item.CopyItemToDocument(doc2, "Body")

Call doc2.Send(True, "Marketing")

Subject: Automatic Notification

Use simple action settings for your agent.

Subject: RE: Automatic Notification

Thanks for your response! This would work fine except I’m not sure how I would specify the criteria to only send a message if the form is about to expire? Is it possible to set up another agent to call the simple action agent?

The expiration date is set up as a text field rather than a date, so I’m not sure if the document selection will work.

Thanks again!

Subject: RE: Automatic Notification

Create a view with Select form =“bla-bla” & ((@now -@TextToTime(textdate) /86,400 > 30)

Create agent with settings all documents in view

in document selection define crated view

in action Send Mail Message

It should take 3 minutes.

Good luck

Subject: RE: Automatic Notification

Thanks to both of you for your reply. I tried to setup the simple action with the view and that works great. The only problem that I have run into is that I need the set this agent up as a scheduled agent. I need the agent to only operate against the view, but that isn’t an option for a scheduled agent. Your help is appreciated!

Subject: RE: Automatic Notification

Simple actions won’t do what you need to do. I’m not sure if this would be beneficial for you or more confusing but here’s an agent I created to run on a daily basis in a helpdesk type of database. The agent would check for a “followup” date that matched today’s date and then build an email to send out using values pulled from the document itself.


Sub Initialize

Dim ses As New NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim docMail As NotesDocument

Dim rtItem As NotesRichTextItem

Dim rtStyle As NotesRichTextStyle

Dim sSearch As String



On Error Goto ErrRtn



sSearch = {Form = "Main" & FollowUpDate = @Today}

Set rtStyle = ses.CreateRichTextStyle

Set db = ses.CurrentDatabase

Set dc = db.Search(sSearch, Nothing, 0)

If dc.Count = 0 Then

	Print "No Follow Ups required today"

	Exit Sub

End If



Set doc = dc.GetFirstDocument

Do Until doc Is Nothing

	Set docMail = New NotesDocument(db)

	Set rtItem = New NotesRichTextItem(docMail, "Body")

	With docMail

		.Form = "Memo"

		.Subject = "Reminder to Follow-up on Down System Log Entry"

		.SendTo = doc.NotifyPeople

		.Principal = "Down Systems Automatic Reminder"

	End With

	

	'write text into email body

	Call rtItem.AppendText("Please follow-up on this problem:")

	Call rtItem.AddNewLine(1)

	rtStyle.Italic = True

	Call rtItem.AppendStyle(rtStyle)

	Call rtItem.AppendText(doc.Problem(0))

	rtStyle.Italic = False

	Call rtItem.AppendStyle(rtStyle)

	If doc.FollowUpText(0) <> "" Then

		Call rtItem.AddNewLine(2)

		Call rtItem.AppendText("These are the Follow-Up Comments:")

		Call rtItem.AddNewLine(1)

		rtStyle.Italic = True

		Call rtItem.AppendStyle(rtStyle)

		Call rtItem.AppendText(doc.FollowUpText(0))

		rtStyle.Italic = False

		Call rtItem.AppendStyle(rtStyle)

	End If

	

	'write link and send email

	Call rtItem.AddNewLine(3)

	Call rtItem.AppendText("Press this link to open up the Down Systems Log Entry =======> ")

	Call rtItem.AppendDocLink(doc, "Down Systems Log Entry")

	Call docMail.Send(False)

	

	'update log entry with date/time email sent

	doc.NotificationSent = Now

	Call UpdateActivityLog("Email Notification Sent at " & Cstr(Now), doc)		

	Call doc.Save(True, False, True)

	Set doc = dc.GetNextDocument(doc)

Loop



Exit Sub

ErrRtn:

Msgbox "Error " & Cstr(Err) & " - " & Error & " occurred at line " & Cstr(Erl), 0 + 16, "Error on Send Notification Agent"

Exit Sub

End Sub


Maybe this code will point you in the right direction. You already mentioned that you don’t want doclinks. You should look into replacing that code with the RenderToRTItem method in the NotesDocument class. That will copy an image of the document into the body of the email.

Hope that helps