Tuesday, January 3, 2012

Bugs: "Element or Navigator is invalid" error when using NotesRichTextNavigator


-->
Let me dive straight into the point.  Assume that I have few document say five documents with a rich text item in each one of it and all of them are created using same form. So don’t bother about minor variations like missing document items etc… To make things simple let me say that these five documents are design equivalent.

Now let me say that I don’t put any values inside the richtext field in 3 document alone. So on the contrary I have values on all the 4 remaining documents.


Now assume that I have the following sort of code in an agent


On Error Goto errhandler
                …….’some code               
                Set dc=db.UnprocessedDocuments
                Set doc=dc.GetFirstDocument
                Set richStyle = session.CreateRichTextStyle
                richStyle.PassThruHTML = true
                                
                While Not doc Is Nothing
                                itr=itr+1
                               
                                Set richText=doc.GetFirstItem("myRtField")
                                Set rtnav=richText.CreateNavigator
                                                               
                                Call rtnav.FindFirstElement(RTELEM_TYPE_TEXTRUN)
                                Call richText.BeginInsert(rtNav)                   ---------------------√†>> when itr=3 this line will error out with error number 4506
                                Call richText.AppendStyle(richStyle)
                                'Call rtnav.GetLastElement(RTELEM_TYPE_TEXTRUN )
                                Call richText.EndInsert
                                Call richText.Update
                                'Call doc.Save(True, False)
                                Set richText=Nothing
                                Set rtnav=Nothing
                                Set doc=dc.GetNextDocument(doc)
                                Print Cstr(itr) & " doc processed"
                Wend
                Exit Sub
errHandler:
                If Err=4506 Then Goto skiploop
                Print Error & " *** occured on line *** " & Cstr(Erl) &"*** with error number *** " & Cstr(Err)
                Exit Sub




As you may understand the since the rich text field in the third document is empty an error with number 4506 will occur.


You can say that one can handle this scenario by using some thing like “IF rtnav Is Nothing Then goto SkipLoop” etc… but it did not work so I managed to loop the control back in my error handler section.


And guess what, the object rtnav becomes unusable. I simply does not set any right values the next time the loop executes and does not accept any values. And so the following error occurs




And alas… the code breaks. Complier does not even make it to the error handler.


So sad L


I think I know a work around for that. So stay tuned

No comments:

Post a Comment