I have an action button on a form. When I press the action button, I want a new memo created and the body populated with text and a doclink for the doc from which I pressed the button.
Question : I know I can use the appenddoclink method when working with a NotesDocument, but how do I do this when working with a NotesUIDocument ?
The code I have is this ;
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim uidoc As NotesUIDocument
Dim UserMailServer As String
Dim UserMailFile As String
Dim UserName As New NotesName(session.UserName)
Dim rtitem As NotesRichTextItem
Dim linkDoc As NotesDocument
Dim strMessage As String
Set workspace = New NotesUIWorkspace
Set session = New NotesSession
Set uidoc = workspace.CurrentDocument
'set a handle on this document as the one for the doclink
Set linkDoc = session.DocumentContext
UserMailServer = session.GetEnvironmentString("MailServer",True)
Set Mailserver = New NotesName(UserMailServer)
UserMailFile = session.GetEnvironmentString("MailFile",True)
'create new document
Set uidoc = workspace.ComposeDocument(MailServer.Abbreviated,UserMailFile,"Memo")
'set subject
Call uidoc.FieldSetText("Subject","DVD Pick Schedule Update")
'build body (inserting message before signature)
strMessage = "Please click on the following link to open the latest pick schedule --> "
strBody = strMessage & Chr$(10) & Chr$(10) & uidoc.FieldGetText("Body")
'set body
Call uidoc.FieldSetText("body",strBody)
This creates the doc fine, and opens it in screen to allow the user to enter a distribution list etc. How Do I add the doclink ?
To do this, grab the user’s mail db, create the back-end document first and then open it in the UI. I’ve modified your code a bit:
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim uidoc As NotesUIDocument
Dim linkDoc As NotesDocument
Dim maildoc As NotesDocument
Dim strMessage As String
'set a handle on this document as the one for the doclink
Set linkDoc = session.DocumentContext
Dim db As New NotesDatabase( "", "" )
Call db.OpenMail
Set maildoc = New NotesDocument( db )
maildoc.Form = "Memo"
maildoc.Subject = "DVD Pick Schedule Update"
strMessage = "Please click on the following link to open the latest pick schedule --> "
Dim rtitem As New NotesRichTextItem(maildoc, "Body")
Call rtitem.AppendText(strMessage)
Call rtitem.AddNewline(2)
Call rtitem.AppendDocLink(linkdoc, "Original Doc Link", "")
Call rtitem.Update
Set uidoc = workspace.EditDocument(True, maildoc)
Thanks for your code. I have tried this, but although a new doc is composed and presented to me in the UI (with strMessage visible) there is no ‘Original Doc Link’ line or the doc link itself.
Looking at notes classes it seems to be impossible to add doclink to uidoc.
But…If you create a button and select simple action, send mail and add doc link, it’s working.!!!
The bad news is that I do not know how they do it, but it is possible.
If I do not find the code, I will turn around the issue by creating an agent with simple action, send mail with link, and call the agent from my lotusscript code…
The way to do it is, you create the NotesDocument object first, fill in a Form field, Subject, etcetera and the Body field containing the stuff you want. Then open the NotesDocument for editing using wksp.EditDocument.
Public Sub Notify (argTo As String, argSubject As String, argText As String)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Set db = session.CurrentDatabase
Set uidoc = workspace.CurrentDocument
Set doc = New NotesDocument( db )
Set rtitem= New NotesRichTextItem (doc,"Body")
Print "Sending Notification"
doc.Form = "Bookmark"
doc.SendTo=argTo
doc.Subject = argSubject
doc.FlowStatus=argText
doc.InheritedDbTitle=Db.Title
Call rtitem.AppendDocLink( uidoc.Document, argText )
Call doc.Send( False)
Below is a sample script that, when executed (in this case, via a button’s click event), generates a mail memo to a particular recipient with an attached doclink that points back to the original document. Note: In
order for this script to run properly, the original document must be saved before the script is executed.
Sample Script:
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
Dim session As New NotesSession
Dim db As NotesDatabase
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set db = session.CurrentDatabase
Set newDoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem(newDoc, "Body" )
Call rtitem.AppendDocLink(doc, "TEST" )
newDoc.Subject = "Here is a link to the document"
newDoc.SendTo = "Your Name"
newDoc.Send( True )
This is almost what I need, although this builds a doc and sends it. What I need is for a doc to be composed and left on the screen for the user to add their own recipients and press ‘send’ themselves