Append Doclink to uidoc?

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 ?

Thanks

Vic

Subject: Append Doclink to uidoc ?

Hi Vic,

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)

I think that should work for you.

Bryce

Subject: RE: Append Doclink to uidoc ?

Hi Bryce,

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.

Any ideas ?

Thanks

Vic

Subject: RE: Append Doclink to uidoc ?

Try workspace.CurrentDocument.Document instead of session.DocumentContext.

Subject: RE: Append Doclink to uidoc ?

Vic,

When you step through the code, is “linkDoc” being populated?

I ran it as an Agent in the Action menu.

Bryce

Subject: Append Doclink to uidoc ?

how do I do this when working with a NotesUIDocument?

Short answer: can’t be done. The classes and methods simply don’t exist in the UI to put anything other than plain text in a rich text field.

Subject: Append Doclink to uidoc ?

Vic,I got the exact same issue.

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…

Ugly, but…

Subject: RE: Append Doclink to uidoc ?

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.

Subject: RE: Append Doclink to uidoc ?

I found a solution (see working procedure below)But I got another issue.

I use a names field as parameter for the argument argTo.

It is working if there is only one name in the field, but If I got a list of names it’s not working.

Here is how I call the sub notify

Notify Source.FieldGetText “NextApprovers”),“sujet”,“text”

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)

End Sub

Subject: RE: Append Doclink to uidoc ?

The SendTo value needs to be an array if there are multiple values. Try this:

doc.SendTo=split(argTo, “,”)

or if you’re delimiting the names with something other than comma, put that character in the quotes.

Subject: Example…

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 )

Subject: RE: Example…

Hi Michael,

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

Thanks

Vic

Subject: Use Formula, not script

txtSubject := “My Subject”;

@Command([EditMakeDocLink]); <= Create a copy of the document currently selected or open in memory

@Command([MailComposeMemo]); <= Compose a new email memo

@Command([EditGotoField];“EnterSendTo”);

@Command([EditInsertText] ; "User Name/ACME);

@Command([EditGotoField];“Subject”);

@Command([EditInsertText] ; txtSubject);

@Command([EditGotoField];“Body”);

@Command([EditPaste]); <= Pastes the doclink that was copied into memory

@Command([EditInsertText] ; "Document Link: ") <= add some nice text :slight_smile:

Done!

Subject: RE: Use Formula, not script

It is work!!!

Thank you very much, :smiley:

Molpapha

Subject: RE: Use Formula, not script

Andrew I could kiss you. My tiresome search is over.

Thanks you!

Diane