Link to home
Start Free TrialLog in
Avatar of snocross
snocross

asked on

AppendDocLink in UI document

Ok guys maybe you can help... I want to be able to insert a link to a backend database in the UI document that I am in.  In my code I have a handle to the UI document (called CurrentDoc) and the backend database (called SourceDb) but it doesn't seem to work in a frontend document.  I want the user to press a button and instantly a doclink gets created and pasted into a rich text field on the document he is looking at.
Avatar of HemanthaKumar
HemanthaKumar

NotesRichTextItem.AppendDocLink is the method to append a link to db or view or doc.

In your case, the uidoc richtext field updates will not be realized until you save the document and close and reopen it.

So after creating the db link, use these methods in a sequence

' After doclink is generated in the rt field
set uidoc = ws.CurrentDocument
set note = uidoc.Document
uidoc.Save
uidoc.close
set uidoc = ws.EditDocument( true, note )
Avatar of snocross

ASKER

Well the problem is I can't even get that far... when I put this code in my lotusscript I get an IS NOT A MEMBER: CREATERICHTEXTITEM error I think because it's a UI document:

Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")

Here is my section of code:

REM Create link and post on project document
     Dim work As New NotesUIWorkspace
     Dim CurrentDoc As NotesUIDocument
     Dim rtitem As NotesRichTextItem
     
     Set CurrentDoc = work.CurrentDocument
     Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")
     
     Call rtitem.AppendText("This is a link to a database template created for this project:")
     Call rtitem.AddNewLine(1)
     Call rtitem.AppendDocLink( NewDb, "Test" )    
     
CreateRichTextItem is a NotesDocument method, it is not UIDocument method.

If you have the field called ProjectLink, then use
set rtitem = CurrentdDoc.GetFirstItem("PriojectLink")

Hello Sno,

here I have done something simelar:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20290601

Therin you see that instead using frontend document object you have to use the asociated backend document (as Heman proposed).
Them main problem is that RichText fields are not rendered to fronted until saved to disk, fronted document closed and opened again. That's the problem.

Change your code like this:
REM Create link and post on project document
  Dim work As New NotesUIWorkspace
  Dim CurrentDoc As NotesDocument 'no UI
  Dim rtitem As NotesRichTextItem
 
  Set CurrentDoc = work.CurrentDocument.Document 'extended
  Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")
 
  Call rtitem.AppendText("This is a link to a database template created for this project:")
  Call rtitem.AddNewLine(1)
  Call rtitem.AppendDocLink( NewDb, "Test" )    
....

You see?

Zvo, I tried your code but I get the error "RTITEM ProjectLink already exists" on the following line of code:

Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")

NOTE: I have a preexisting editable rich text field called ProjectLink
Do all RTItems with Backend...

I prefer Zvo's following approach !

Set CurrentDoc = work.CurrentDocument.Document

Hi Bro!


Zvo, I tried your code but I get the error "RTITEM ProjectLink already exists" on the following line of code:

Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")

NOTE: I have a preexisting editable rich text field called ProjectLink
Heman, I tried plugging your rtitem code into Zvo's and it eliminated the error but the doclink never appears on the document even after closing and reopening:

REM Create link and post on project document
     Dim work As New NotesUIWorkspace
     Dim CurrentDoc As NotesDocument 'no UI
     Dim rtitem As NotesRichTextItem
     
     Set CurrentDoc = work.CurrentDocument.Document 'extended
     'Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")
     Set rtitem = CurrentDoc.GetFirstItem("ProjectLink")
     
     Call rtitem.AppendText("This is a link to a database template created for this project:")
     Call rtitem.AddNewLine(1)
     Call rtitem.AppendDocLink( NewDb, "Test" )    
     Call CurrentDoc.Save( False, True )


Hello Arun!
You have now two options:
1: recreating the RT item by removing the present one and create a new item whit same name.
2: fetch the present RT item and append text.

Take care that in second way you have to declare the rtitem as Variant, like this:
Dim rtitem As Variant
Set rtitem = CurrentDoc.GetFirstItem("ProjectLink")
If ( rtitem.Type = RICHTEXT ) Then ...

If you prefer the recreation method then simply call the Remove method:
Dim rtitem As NotesRichTextItem
Set CurrentDoc = work.CurrentDocument.Document
Call CurrentDoc.RemoveItem("ProjectLink")
Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")


Hello Sno,

how about this:
Sub Click(Source As Button)
  Dim work As New NotesUIWorkspace
  Dim uidoc As NotesUIDocument
  Dim CurrentDoc As NotesDocument
  Dim rtitem As Variant
  Dim NewDb As NotesDatabase
  Set uidoc = work.CurrentDocument
  Set CurrentDoc = uidoc.Document
  uidoc.Close
  Doevents
  Set NewDb = CurrentDoc.ParentDatabase
  Set rtitem = CurrentDoc.GetFirstItem("ProjectLink")
  If (rtitem Is Nothing) Then Set rtitem = CurrentDoc.CreateRichTextItem("ProjectLink")
  If ( rtitem.Type = RICHTEXT ) Then
    Call rtitem.AppendText("This is a link to a database template created for this project:")
    Call rtitem.AddNewLine(1)
    Call rtitem.AppendDocLink( NewDb, "Test" )
    CurrentDoc.Form = "ProjectDoc"
    Call CurrentDoc.Save( False, True )  
  End If
  Set uidoc = work.EditDocument(EditMode, CurrentDoc)
  CurrentDoc.SaveOptions = "0"
End Sub

Does it work for you?

Sno, after saving the changes to the document you have to reopen the document by closing the current one.

Set uidoc = work.EditDocument(EditMode, CurrentDoc)
 in zvonko's script also does the same trick.
ASKER CERTIFIED SOLUTION
Avatar of zvonko
zvonko

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Anytime pal.
Thank you very much everyone, this did the trick!  It was very frustrating yet it seemed so simple.
When we did not fix that, who else should then :-)

;-)

There is a nice saying in tamil...

ippadai thorkin yeppadai vellum....
Meaning,
If this army loses which will win ???

:-)
Right! :-)

The words sound good Arun; if I where not so lazy I would learn Tamil.

My fathers second sun (my brother :-) is learning Thai. He can even write this strange letters!
(and read it afterwards :-)