I’m rebuilding an agent from Formula language to Lotus script because I need to add onto the agent to create a doclink utilizing lotus script. Ultimately the code will create a doclink from a Notes mail message to an Exchange mail recipient. The original formula language is this:
NL := @NewLine;
TAB := @Char(9);
currUser := @UserName;
FIELD doc_date := doc_date;
@MailSend(SendTo; currUser; “”;
"Some Text Here";
"Some Text Here:" +
NL + NL +
TAB + "Document ID#:" + TAB + DocumentID + NL +
TAB + "Question:" + TAB + Title + NL +
TAB + "Modified by:" + TAB + currUser + NL +
TAB + "Due Date:" + TAB + @Text(doc_date) + NL +
TAB + "User Comments:" + TAB + comments + NL;
"Click to view ===>>> "; [IncludeDoclink]);
SELECT@All
Here is the script that I’m using to mimic the functionality of the above code (and I can’t get the document to save):
Dim ws As New notesuiworkspace
Dim uidoc As NotesUIDocument
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim rtitem As New NotesRichTextItem(doc, "Body")
Dim username As Variant
Set db = sess.CurrentDatabase
Set uidoc = ws.Currentdocument
doc.form = "Memo"
username = Evaluate("@Name([CN];@UserName(0))")
Call rtitem.AppendText("Document ID#: ")
Call rtitem.AddNewline(1)
Call rtitem.AppendText("Question: ")
Call rtitem.AddNewline(1)
Call rtitem.AppendText("Modified by: ")
Call rtitem.AddNewline(1)
Call rtitem.AppendText("Due Date: ")
Call rtitem.AddNewline(1)
Call rtitem.AppendText("User Comments: ")
Call rtitem.AddNewline(1)
Call rtitem.AppendText("Click to view ===>>> ")
I then add the code for the doclink:
'create ndl file
docID = doc.UniversalID
’ Links of a local database will not work
If db.server = "" Then
Msgbox "You are not allowed to send a link of a local database", 4112, "Local Links Not Allowed"
Exit Sub
Else
’ create Replica line for link
ReplicaID="<REPLICA " & Left$(db.ReplicaID, 8) & ":" & Right$(db.ReplicaID, 8) & ">"
End If
ViewID = ""
’ You need a default view in the database for the link to work
Forall x In db.Views
If x.IsDefaultView Then
’ Build View line for the link
ViewID = "<VIEW OF" & Left$(x.UniversalID, 8) &":"&Mid$(x.UniversalID, 9, 8)&"-"&"ON"&Mid$(x.UniversalID, 17, 8)&":"&Right$(x.UniversalID, 8)&">"
Exit Forall
End If
End Forall
’ Make sure a default view was found
If ViewID = "" Then
’ View handle was never built so link would give a view error, warn user and exit routine
Msgbox "This database does not contain a default view." & Chr$(10) & Chr$(10) & "Please contact your database manager!", 4112, "Default View Not Found"
Exit Sub
End If
’ Create the NoteID, hint server and file name for the link
NoteID = "<NOTE OF" & Left$(docID, 8) &":"&Mid$(docID, 9, 8)&"-"&"ON"&Mid$(docID, 17, 8)&":"&Right$(docID, 8)&">"
HintServer = "<HINT>"& db.server &"</HINT>"
fileNum% = Freefile()
fileName2 = Curdir$+"\TimeDoc.ndl"
’ Build the link file
Open fileName$ For Output As fileNum%
Write #fileNum%, "<NDL>"
Write #fileNum%, ReplicaID
Write #fileNum%, HintServer
Write #fileNum%, ViewID
Write #fileNum%, NoteID
Write #fileNum%, "</NDL>"
Close fileNum%
'Pass the fileName$ to email
Call MailNotify(db, doc,fileName2 )
'delet the temp file
Kill fileName2
Email:
'embed the file
Set object = rtitem.EmbedObject _
( EMBED_ATTACHMENT, "", fileName2)
Call doc.Save(True, False)
Call doc.Send(True, username)
Another set of eyes would be greatly appreciated and I thank you for your time.