• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 727
  • Last Modified:

NotesRichTextNavigator issue...

I am having a problem with adding/managing a table in a NotesRichtextField with a NotesRichtextNavigator.  The problem occurs after a user opens the destination document and saves it.  After they do that, the Set linksTable = linksNav.GetFirstElement (RTELEM_TYPE_TABLE) no longer finds the table(which reaks havoc on my code).  I am simply looking for a way to manage a link in the reference doc (in another notes db on same server) back to the current doc.  I need to be able to remove the link if the current doc changes reference docs or if the current doc is deleted.  Here is the code I have but I am VERY open to any solution.

Just a note, the following code works perfectly until a user opens, modifies and saves the reference doc.

Sub Postsave(Source As Notesuidocument)
      Dim referenceDB As NotesDatabase
      Dim referenceView As NotesView
      Dim session As New notessession
      Dim originalRefDoc As NotesDocument
      Dim newRefDoc As NotesDocument
      newValue = source.FieldGetText ("ReferenceNumberTxt")
      newSource = source.FieldGetText ("Source")
      Dim testString As String
      Set newRefDoc = getRefDoc (newValue, newSource, referenceDB)
      If newRefDoc Is Nothing Then
      Else
            Call removeDocLink (newRefDoc, source.Document)
            Call addDocLink (newRefDoc, source.Document)
      End If
      If newValue = originalValue Then Exit Sub
      If originalSource = "" Then
            originalValue = source.FieldGetText ("ReferenceNumberTxt")
            originalSource = source.FieldGetText ("Source")
            Exit Sub
      End If
      Set originalRefDoc = getRefDoc (originalValue, originalSource, referenceDB)
      If originalRefDoc Is Nothing Then
      Else
            Call removeDocLink (originalRefDoc, source.Document)
      End If
      originalValue = source.FieldGetText ("ReferenceNumberTxt")
      originalSource = source.FieldGetText ("Source")
      
End Sub


Function getRefDoc (refDocKey As String, source As String, referenceDB As NotesDatabase) As Variant
      Dim session As New NotesSession
      Dim referenceView As NotesView
      Select Case Ucase (source)
      Case "REQUEST", "PROJECT"
            Set referenceDB = session.GetDatabase (session.CurrentDatabase.Server, "\corp\ISGreq.NSF")
            Set referenceView = referenceDB.GetView ("(All By Number)")
      Case "DISPATCH"
            Set referenceDB = session.GetDatabase (session.CurrentDatabase.Server, "\corp\Dispatch\Dispatch.NSF")
            Set referenceView = referenceDB.GetView ("Ticket Lookup")
      Case Else
            Messagebox "The reference source " + source + " is not recognized.", 0, "Invalid value in Source..."
            Exit Function
      End Select
      Set getRefDoc = referenceView.GetDocumentByKey (refDocKey)
End Function




Sub addDocLink (refDoc As NotesDocument, changeControlDoc As NotesDocument)
      Dim linksField As NotesRichTextItem
      Dim session As New NotesSession
      Dim linksNav As NotesRichTextNavigator
      Dim linksTable As NotesRichTextTable
      Set linksField = refDoc.GetFirstItem ("ChangeControlLinks")
      If linksField Is Nothing Then
            Set linksField = New NotesRichTextItem (refDoc, "ChangeControlLinks")
      End If
      Set linksNav = linksField.CreateNavigator
      Set linksTable = linksNav.GetFirstElement (RTELEM_TYPE_TABLE)
      If linksTable Is Nothing Then
            Redim labels (0) As String
            labels (0) = "Change Control " + changeControlDoc.ItemId (0)
            Call linksField.AppendTable (1,1, labels)
      Else
            Call linksTable.AddRow (1)
            Dim labelCount As Integer
            Forall label In linksTable.RowLabels
                  Redim Preserve labels (labelCount) As String                  
                  labels (labelCount) = label
                  labelCount = labelCount + 1
            End Forall
            labels (Ubound (labels)) =  "Change Control " + changeControlDoc.ItemId (0)
            linksTable.RowLabels = labels
      End If
      Call linksNav.FindLastElement (RTELEM_TYPE_TABLECELL)
      Call linksField.BeginInsert(linksNav)
      Call linksField.AppendDocLink (changeControlDoc, "Change Control " + changeControlDoc.ItemId (0))
      Call linksField.AddNewline(1)            
      Call linksField.AppendText (changeControlDoc.ReqChangeDesc (0))
      Call linksField.EndInsert
      Call refDoc.Save (True,False)
      
End Sub

Sub removeDocLink (refDoc As NotesDocument, changeControlDoc As NotesDocument)
      Dim linksField As NotesRichTextItem
      Dim linksNav As NotesRichTextNavigator
      Dim linksTable As NotesRichTextTable      
      Set linksField = refDoc.GetFirstItem ("ChangeControlLinks")
      If linksField Is Nothing Then
            Set linksField = New NotesRichTextItem (refDoc, "ChangeControlLinks")
      End If
      Set linksNav = linksField.CreateNavigator
      Set linksTable = linksNav.GetFirstElement (RTELEM_TYPE_TABLE)
      If linksTable Is Nothing Then
      Else
            Dim labelCount As Integer
            Forall label In linksTable.RowLabels
                  If label =  "Change Control " + changeControlDoc.ItemId (0) Then
                        If linksTable.RowCount = 1 Then
                              Call refDoc.RemoveItem ("ChangeControlLinks")
                        Else
                              Call linksTable.RemoveRow(1, labelCount + 1 )
                        End If
                        Call refDoc.Save (True,False)
                        Exit Sub
                  End If
                  labelCount = labelCount + 1
            End Forall
      End If
End Sub

0
dparden
Asked:
dparden
  • 5
  • 5
1 Solution
 
dpardenAuthor Commented:
BTW, the ChangeControlLinks field in the reference doc is displayed with a RichText field.  I have tried 'Computed' and 'Editable' with the same results.
0
 
qwaleteeCommented:
There have always been issues documented with working on rich text fields using LotusScript while the rich text field s stil open in the UI.  You may be able to get this to work by:
    Saving
    Closing UI Doc (use the immediate options)
    Modifying RTF
    Reopening+switch back to edit mode (if you intend the user to see results immediately)
0
 
qwaleteeCommented:
Also...

Don't use "\corp\ISGreq.NSF" -- it should be "corp\ISGreq.NSF" (without the leading backslash).

I don't know why you pass ReferenceDB as a parameter to GetRefDoc, since you never use ReferenceDB outside the GetRefDoc function.

I also don't know why you have the "if originalSource =" block... do you use originalSource again later?  And why would you only set it if the orignal source were blank?  I don't know your business logic, but it would seem to me that if the user went through several passes of this, the "original" shoudl really always be the previous value, not necessarily the value that was known when first opening the document, or, if there was none, the first value ever available since opening the document.  Because that is what your code does imply -- only on open, or if none at that time, only the first time set.  But that obvisouly iisn't your intention, since you set originalVale at the end of the routine anyway!  So, do one or the other, both is a contradiction.

Your "blank if block followed by an else" will work, but is somehwta awkward.  Try removing the ELSE and using teh following IF statements instead:
     If Not (newRefDoc Is Nothing) Then
     If Not (originalRefDoc Is Nothing) Then

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dpardenAuthor Commented:
To make sure I understand what you mean...Are you refering to adding rich text into the currently open document?  I don't think that is what I am doing here.

The reference Doc is never opened through the UI while the link is being added.  The link is added to the reference document when the user saves the change control doc.

The problem occurs if after the link has been added to the reference doc, the reference doc is opened through a view, modified and saved.  The next time the program above runs, the table is not found in the rich text field of the reference document.

I have some other options for accomplishing my required functionality, but none of them are quite as slick as this one would have been if (of course that's a pretty big if at this point) I could have gotten it to work.
0
 
qwaleteeCommented:
OK, I may have misunderstood. What you are saying is that the modified rich text field does not repsond properly to:

    linksNav.GetFirstElement (RTELEM_TYPE_TABLE)

Is that correct?  What DOES get returned?
0
 
dpardenAuthor Commented:
Yes, that is correct.  It returns 'nothing'.  This only occurs after the reference document has been edited and saved.  As long as the reference document is not edited and saved, the code works as expected.  Once the document is edit and saved, the code never works for that reference document again.
0
 
dpardenAuthor Commented:
I am still interested in some insite to what I am doing wrong here.  I have developed a work-around for my current application but it has some shortcomings.  Additionally, there are several other apps I would like to use similar functionality.
0
 
qwaleteeCommented:
dparden,

> I am still interested in some insite to what I am doing wrong here.  I have developed a
> work-around for my current application but it has some shortcomings.  Additionally, there
> are several other apps I would like to use similar functionality.

It isn't you.  NotesRichTextNavigator is only half-baked.

- qwaletee
0
 
dpardenAuthor Commented:
I had some more descriptive, less professional words for it.  Thanks for your help.  Not the answer I wanted, but it was what I expected.  Anyway, the solution we came up with had some additional benefits the users liked.

Sorry for the delay in accepting your answer, I didn't get the notification email.
0
 
qwaleteeCommented:
No problem.  What did you end up going with?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now