Solved

AppendDocLink in UI document

Posted on 2002-05-17
17
1,569 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Expert Comment

by:zvonko
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Anytime pal.
0
 
LVL 5

Author Comment

by:snocross
Comment Utility
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
Comment Utility
When we did not fix that, who else should then :-)

0
 
LVL 9

Expert Comment

by:Arunkumar
Comment Utility
;-)

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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now