Solved

AppendDocLink in UI document

Posted on 2002-05-17
17
1,600 Views
Last Modified: 2013-12-18
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.
0
Comment
Question by:snocross
  • 6
  • 5
  • 4
  • +1
17 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7016322
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 )
0
 
LVL 5

Author Comment

by:snocross
ID: 7016347
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" )    
     
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7016393
CreateRichTextItem is a NotesDocument method, it is not UIDocument method.

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

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:zvonko
ID: 7016404
Hello Sno,

here I have done something simelar:
http://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?

0
 
LVL 5

Author Comment

by:snocross
ID: 7016439
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
0
 
LVL 9

Expert Comment

by:Arunkumar
ID: 7016461
Do all RTItems with Backend...

I prefer Zvo's following approach !

Set CurrentDoc = work.CurrentDocument.Document

Hi Bro!


0
 
LVL 5

Author Comment

by:snocross
ID: 7016467
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
0
 
LVL 5

Author Comment

by:snocross
ID: 7016472
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!
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7016510
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")


0
 
LVL 10

Expert Comment

by:zvonko
ID: 7016567
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?

0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7016877
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.
0
 
LVL 10

Accepted Solution

by:
zvonko earned 50 total points
ID: 7016916
Thank you Heman for cut'n pasting my code :-)
Without this I would not notice that EditMode was not defined!

Here the correct version:
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
  Dim EditMode As Integer
  Set uidoc = work.CurrentDocument
  Set CurrentDoc = uidoc.Document
  EditMode = uidoc.EditMode
  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

Thanks Heman <|:-)



0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7017011
Anytime pal.
0
 
LVL 5

Author Comment

by:snocross
ID: 7017223
Thank you very much everyone, this did the trick!  It was very frustrating yet it seemed so simple.
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7017280
When we did not fix that, who else should then :-)

0
 
LVL 9

Expert Comment

by:Arunkumar
ID: 7017485
;-)

There is a nice saying in tamil...

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

:-)
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7019597
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 :-)

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question