Avatar of devguru001
devguru001
Flag for South Africa asked on

NotesRichTextNavigators, NotesRichTextRanges and NotesRichTextSections

Hi,

So I have an interesting problem. Here is the scenario. We have a helpdesk db where sometimes it's required to contact the user, keeping them up to date or whatever the reason may be. So from the helpdesk I would create a new memo. This memo would contain whatever you want to ask or tell the user and at the end of the email there is a section called "---------------------------------------------------------------------------------------History---------------------------------------------------------------------------------------". This section contains all of the correspondence between the helpdesk and the user. The history is copied from a response document (called a summary document) connected to the specific helpdesk call that basically contains all of the correspondence. This history section is a section that contains other sections. See image below. So I need to, after the email has been sent, to delete the history section and add the current correspondence back into the helpdesk. Reason for deleting the history is because that history is stored in a summary document so we only need the latest correspondence.

Problem is when I want to navigate to the history section and setting the range and all and then delete everything from the history downward, Notes just doesn't delete the history section too. It deletes anything AFTER the history section but not the history section INCLUDED.

Here is some sample code that I was playing around with but no joy. Your assistance in this will be GREATLY appreciated.

Code:

Sub Click(Source As Button)
      Dim ws As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      
      Dim rti As NotesRichTextItem
      Dim rtnav As NotesRichTextNavigator
      Dim rts As NotesRichTextSection
      Dim rtrangesec As NotesRichTextRange
      Dim rtt As NotesRichTextTable
      Dim count As Integer
      Dim strtitle As String
      
      
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.Document
      
      If uidoc.EditMode Then
            uidoc.EditMode = False
      End If
      
      Set rti = doc.GetFirstItem("Body")
      Set rtnav = rti.CreateNavigator
      
      strtitle = "---------------------------------------------------------------------------------------History---------------------------------------------------------------------------------------"
      
      If rtnav.FindFirstElement(RTELEM_TYPE_SECTION) Then
            
            Count = 0
            Set rts = rtNav.GetFirstElement(RTELEM_TYPE_SECTION)
            
            If RTS Is Nothing Then
                  Messagebox("Did not get first section")
            End If
            
            While Not  rts  Is Nothing            
                  Count = count + 1
                  If RTS.Title = STRTitle Then
                        Set rtrange = rti.CreateRange
                        If RTNav.FindNthElement(RTELEM_TYPE_SECTION, count) Then                        
                              Messagebox(rts.Title)
                              Call RTNav.SetPositionAtEnd(RTNav)            
                              Call rtrange.SetBegin(rtnav)                        
                              
                              Call rtrange.Remove                              
                              Set RTS = Nothing
                        End If
                  Else                        
                        Set rts = rtNav.GetNextElement(RTELEM_TYPE_SECTION)            
                  End If
            Wend
      End If
      
      Call doc.Save(True, True)

End Sub
Memo.png
Lotus IBM

Avatar of undefined
Last Comment
Sjef Bosman

8/22/2022 - Mon
Sjef Bosman

Can you try to avoid messing with RT-fields? IMHO you should just store the history in a separate field. In a later stage, you can assemble whatever you want easily.
devguru001

ASKER
I did try storing it in another field but problem is the recipient doesn't then see it because they don't have that field on their memo form.
ASKER CERTIFIED SOLUTION
Sjef Bosman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jjphardy

If you are trying to remove just the section, why not use the remove method for a section.

rts.remove

If you want to delete the section and everything below it, you have removed everything below it. Then call the remove method.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
devguru001

ASKER
Hi guys,

I have found a solution that alleviates the problem with working with the richtextnavigator so much. I compose the email in the helpdesk db, then when the helpdesk person clicks on Send Mail, the uidoc closes but I still have a handle on the notesdocument, I then add the email into my summry, I add the history at the end of the body field and send the mail. Problem solved. Thanks for the feedback. I think this was the best solution for me to follow.
devguru001

ASKER
I only noticed after I found my solution that the last question he asked was what I did.
Sjef Bosman

So why not an "A" ?  ;-)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.