Solved

AppendDocLink in UI document

Posted on 2002-05-17
17
1,584 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to access Names.nsf DB from a C# application 14 1,533
Recent Contacts - Lotus Notes 10 648
Add a cc field to email code 3 111
Disable some Lotus eMail users for a period of time 4 67
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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