This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal


Sep 1, 2016, 5:37 PM
3 Posts

Insert a doclink in a richtext

  • Category: Application Development
  • Platform: Windows
  • Release: 9.0
  • Role: Developer
  • Tags:
  • Replies: 4

Hello,

 

I have some code that looks for an attachment in a richtext and replaces it with a doclink (doc that I have created in another DB) My problem is that the doclink is added at the end of the text and not where the attachment is located.

 

Is there anyway to add the doclink at the position where the attachment is?

 

    Dim rtitem As NotesRichTextItem
    Dim NaneOfFile As Variant
    
    Set rtitem = doc.GetFirstItem( Item.Name ) 
    If ( rtitem.Type = RICHTEXT ) Then

            If Not IsEmpty (rtitem.EmbeddedObjects) Then
            
            ForAll o In rtitem.EmbeddedObjects
                stop
               
                Call AttachementDetacher(o, NaneOfFile )
                
                Dim docAttachment As New NotesDocument(dbAttachment)
                Dim rtitemATT As New NotesRichTextItem(docAttachment, "Body")
                
                ' create the doc in the DB attachment
                Call OutAttachmentAttach(o, NaneOfFile , rtitemATT, doc, docAttachment, Item.Name)
                
                ' we delete the attachment and add the doclink of the document attachment 
                
                Call rtitem.AddNewLine( 1 )
            '    Call rtitem.AppendText( NaneOfFile )
            '    Call rtitem.AppendText( " " )
                Call rtitem.AppendDocLink( docAttachment, NaneOfFile )
            '    Call rtitem.AddTab( 1 )
                Call doc.Save( True, True )
    
            End ForAll

many thanks,

Alena 

Sep 1, 2016, 10:15 PM
107 Posts
NotesRichtextNavigator
You can use class NotesRichtextNavigator and its companion classes to control where in a rich text field things are inserted. Expect a steep learning curve, however, if it's the first time you are using those classes.
Sep 6, 2016, 7:58 PM
82 Posts
Sample RICH lotusscript code ...
Dim reportDoc As NotesDocument,linksItem As NotesRichTextItem
Dim rtstyle As NotesRichTextStyle,rtnav As NotesRichTextNavigator,rtt As NotesRichTextTable

Sub CreateReportDocTable()
        Set reportDoc = thisDB.createdocument
        'create table with links
        Set rtstyle = session.CreateRichTextStyle        
        Set linksItem = New NotesRichTextItem(reportDoc, "DispStat")
        CreateSummaryTable linksItem
        Set rtnav = linksItem.CreateNavigator
        Call rtnav.FindFirstElement(RTELEM_TYPE_TABLE)
        Set rtt = rtnav.GetElement
        WriteColumnsLabels linksItem,rtnav,rtStyle
End Sub

Sub WriteColumnsLabels(rtitem As NotesRichTextItem,rtnav As NotesRichTextNavigator,rtStyle As NotesRichTextStyle)  'creates static column headers (labels) in summary table
        Dim column As Integer
        Call InitRTStyle(rtstyle, True,10,COLOR_BLACK)  'font style for summary table column labels
        Call rtitem.AppendStyle(rtstyle)
        Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
        For column = 1 To 6 Step 1
                Call rtitem.BeginInsert(rtnav)
                Select Case column
                Case 1
                        Call rtitem.AppendText("Date")
                Case 2
                        Call rtitem.AppendText("Platform")
                Case 3
                        Call rtitem.AppendText("Type")
                Case 4
                        Call rtitem.AppendText("Attempted")
                Case 5
                        Call rtitem.AppendText("Passed")
                Case 6
                        Call rtitem.AppendText("Link")
                End Select
                Call rtitem.EndInsert
                Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
        Next                        
        Call InitRTStyle(rtstyle, False,9,COLOR_BLACK)  'switch back to normal font style
        Call rtitem.AppendStyle(rtstyle)
End Sub

Sub InitRTStyle(rtstyle As NotesRichTextStyle, STRONG As Boolean,fontSize As Integer,textColor As Integer)
        rtstyle.Bold = STRONG
        rtstyle.FontSize = fontSize
        rtstyle.NotesColor = textColor
        'rtstyle.NotesFont = Font_Courier
End Sub

Sub WriteReportLinks(sDate As String,sPlatform As String,sType As String, sAttempted As String,sPassed As String, ndBVTDoc As NotesDocument)
        Dim column As Integer
        If rtt.Rowcount < 100 Then        
                Call rtt.AddRow(1)
                Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
                For column = 1 To 6 Step 1
                        Call linksItem.BeginInsert(rtnav)
                        Select Case column
                        Case 1
                                Call linksItem.AppendText(sDate)
                        Case 2
                                Call linksItem.AppendText(sPlatform)
                        Case 3
                                Call linksItem.AppendText(sType)
                        Case 4
                                Call linksItem.AppendText(sAttempted)
                        Case 5
                                Call linksItem.AppendText(sPassed)
                        Case 6
                                linksItem.appenddoclink ndBVTDoc,"link to bvt report"
                End Select
                        Call linksItem.EndInsert
                        Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)        
                Next
        End If
End Sub
Sep 7, 2016, 12:09 PM
3 Posts
rtnav

Thanks I will work something with your help....

 

Alena.

Sep 7, 2016, 7:13 PM
3 Posts
Oh my ... issues with adding the doclink to the right position in the richtext

Hi,

I am trying to add a doclink where the attachment/file was in the middle of the text. I cannot see it in the debugger but I assumed that rtnav would have the position of the attachment, it still adds the doclink at the end of the richtext.

From this function I tried to get the location of the attachment detach it and then add the doclink

Dim rtitem As NotesRichTextItem
    Dim InfoFileNameAs Variant
    Dim rtnav As NotesRichTextNavigator
    Dim obj As NotesEmbeddedObject
    
    Set rtitem = doc.GetFirstItem( Item.Name ) 
    If ( rtitem.Type = RICHTEXT ) Then

            If Not IsEmpty (rtitem.EmbeddedObjects) Then
            
            ForAll o In rtitem.EmbeddedObjects
                Stop
                Set rtnav = rtitem.CreateNavigator
                Set obj = rtnav.GetFirstElement(RTELEM_TYPE_FILEATTACHMENT)
                
                While Not (obj Is Nothing)
                    ' here is where we detach the file
                    Call AttachementDetacher(obj, InfoFileName)
                    
                    Dim docAttachment As New NotesDocument(dbAttachmentOpen)
                    Dim rtitemATT As New NotesRichTextItem(docAttachment, "Body")
                    
                    ' WE create the new doc in the Attachments file database
                    Call GetOutFileAttachment(obj, InfoFileName, rtitemATT, doc, docAttachment, Item.Name, rtnav)
                     ' the function GetOutFileAttachment below I want to add the link and via the rtnav (I suppose that it                     '    contains the position where the attachment was)
                    '
                        
                    Call rtitem.AddNewLine( 1 )
                    Call rtitem.AppendDocLink( docAttachment, InfoFileName)
                    Call doc.Save( True, True )
                    
                    
                    Set obj = rtnav.GetNextElement(RTELEM_TYPE_FILEATTACHMENT)
                    
                Wend
            
            End ForAll
        End If
    End If
End Function


Function GetOutFileAttachment(o, InfoFileName, rtitemATT, doc, docAttachment, Item, rtnav)
    Dim itemName As NotesItem

    If docAttachment Is Nothing Then
        Call rtitemATT.BeginInsert(rtnav)' ********* I cannot see it in the debugger but I assumed that rtnav had the position of the attachment, it still addes the doclink at the end of the richtext.
        Call rtitemATT.embedobject(Embed_Attachment, "", "C:\temp\" + o.name ) 
        Call doc.Save( True, True )
    Else        
        docAttachment.Form = "Attachments"
        If doc.form(0) = "frmDSER" Then
            
            docAttachment.Dem_No = doc.Dem_No(0)
            docAttachment.Date_Creation = CStr(doc.Date_Creation(0))
            docAttachment.InfoFileName = InfoFileName
        Else
            docAttachement.Dos_No = doc.No_Dos_Reponse(0)
            docAttachement.Date_Creation = CStr(doc.Date_Creation(0))
            docAttachement.InfoFileName = InfoFileName 
        End If
        
        docAttachement.NoID = doc.REF(0) 
        docAttachement.AttachProvChamp = Item 
        docAttachement.AttachProvDoc = doc.form(0)
        
        Call rtitemATT.embedobject(Embed_Attachment, "", "C:\temp\" + o.name ) 
        Call docAttachment.Save( True, True )
    End If
    
    Kill "C:\temp\" + o.name 
    Call o.remove 
End Function

 


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal