Lotus Notes Script AppendDocLinnk

I want to append this e-mail with a doc link to the current document. Right now, my script only composes the e-mail message based on fields and there is no document link attached. I’m not really savvy with Lotus script so what can I do to modify this current script to include a document link?

Sub Click(Source As Button)

Dim maildb As New NotesDatabase( "", "" )

Dim doc As NotesDocument

Dim workspace As New NotesUIWorkspace     

Set uidoc = workspace.CurrentDocument

SendToManager$ = uidoc.FieldGetText ("Manager")

SendToApprover$ = uidoc.FieldGetText ("Approver")



Call maildb.OpenMail

Set uidoc = workspace.ComposeDocument   (maildb.Server, maildb.FILEPATH, "Memo")

Call uidoc.FieldSetText (SendTo$, SendToManager$ + ", " + SendToApprover$)

End Sub

Subject: Lotus Notes Script AppendDocLinnk

Wadi,

You can only append a doc link to a NotesRichTextItem, which would involve you grabbing the backend NotesDocument object and also creating a NotesRichTextItem object as well.

I would look at the Notes help for NotesDocument and NotesRichTextItem. Also look at the NotesUIDocument help, particularly the Document property of the NotesUIDocument class.

brandt

Subject: Lotus Notes Script AppendDocLinnk

Modify this script and it will do what you want. The parts you mainly care about pertain to the variable rtitem. Note what it is, and how it works. If you’re using an existing document, it’s faster to use the backend classes than the ui versions. Generally easier to work with too. xdoc is the variable assigned to the mail document. The array contains the names of the persons to send to.

Sub Initialize

%REM

Run this agent nightly. It runs on all documents and sends an e-mail with doc links to the approver.

Documents should be included if

  1. They are status Awaiting Approval AND

  2. They are within 7 days of the due date OR

  3. They are on or past the due date.

%END REM

Dim s As New notessession

Dim db As NotesDatabase

Dim view As notesview

Dim doc As notesdocument

Dim dc As notesdocumentcollection

Dim dcp As notesdocumentcollection

Dim vcount As Integer

Dim vpcount As Integer



Dim weblink As String

Dim servername As String

Dim viewname As String

Dim temp As String	

Dim ret As Variant

Dim delim As String



Dim dateTime As New NotesDateTime( Today )

Dim dateTime1 As Variant

Dim xdoc As NotesDocument

Dim rtitem As NotesRichTextItem



Set db = s.CurrentDatabase

Set view = db.GetView("INVOICES BY STATUS")



servername = db.Server

'need to turn this into a web friendly name



eq% = Instr(servername, "=")

slash% = Instr(servername, "/") -1



servername = Left$(servername, slash%) 'characters up to the slash

servername = Right$(servername, Len(servername) - eq%)



'split the view and replace the spaces with +

viewname = view.Name

delim = " "

ret = Split(viewname, delim)





For a = 0 To Ubound(ret)

	temp = temp + ret(a) + "+"

Next



temp = Left$(temp, Len(temp)-1)'Remove the trailing + sign

viewname = temp



'Get all the open documents and put them in a document collection

Set dc = view.GetAllDocumentsByKey("Awaiting Approval")

Set doc = dc.GetFirstDocument	



vcount = 0



Call dateTime.AdjustDay( +7 ) 'Want to check out 7 days from today

dateTime1 = dateTime.DateOnly



Call rtitem.AddTab(1)

Call rtitem.AppendText("Invoice")

Call rtitem.AddTab(1)

Call rtitem.AppendText("Due Date")

Call rtitem.AddTab(1)

Call rtitem.AppendText("Web Link")

Call rtitem.AddNewline(1)

Call rtitem.AppendText("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")

Call rtitem.AddNewline(1)



Do While Not (doc Is Nothing)

	

	Set xdoc = New NotesDocument( db )

	Set rtitem = New NotesRichTextItem( xDoc, "Body" )

	xdoc.Form = "Memo"

	

'needs to go to the approver

’ xdoc.sendTo = “joel phelan/steinmart”

	xdoc.sendto = doc.approver(0)

	

	'Check the creation date to make sure it is <= 7 days from now.

	cdate$ = Cstr(doc.Created)

	If Cdat(cdate$) <= Cdat(Cstr(datetime1)) Or Cdat(cdate$) > Today Then

		vcount = vcount + 1

		weblink = "http://" + servername + "/" + db.FileName + "/" + viewname + "/" + doc.UniversalID + "?opendocument"

		

		Call rtitem.AppendDocLink( doc, db.Title )				

		Call rtitem.AddTab(1)

		Call rtitem.AppendText(doc.invoicenumber(0))

		Call rtitem.AddTab(1)

		Call rtitem.AppendText(doc.datedue(0))

		Call rtitem.AddTab(1)

		Call rtitem.AppendText(weblink)

		Call rtitem.AddNewline(1)

		

		omessage$ ="This document has expired or will expire in the next 7 days."

		xdoc.subject =omessage$

		Call xdoc.Send( False )			

		

	End If

	

	Set doc = dc.GetNextDocument(doc)

Loop

End Sub