FindAndReplace not working on web? (RichText issue)

Hi

Im having a strange problem. I have a routine that assemples several RichText fields in different documents into a new document, which is shown on the web.

This is working perfectly, but i also need to replace some of the words, and i cant make it work, so what am i doing wrong.

I have the basic code here:

dim session as new NotesSession

dim webdb as NotesDatabase, crmdb as NotesDatabase

dim view as NotesView

dim webdoc as NotesDocument, rtdoc as NotesDocument

dim rt_target as NotesRichTextItem, rt_source as NotesRichTextItem

dim rtrange as NotesRichTextRange

set webdb = session.currentDatabase

set crmdb = session.getDatabase(“…”)

set view = crmdb.getView(“…”)

set webdoc = webdb.createDocument

set rt_target = new NotesRichTextItem(webdoc, “Body”)

set rtdoc = view.getFirstDocument()

do while not rtdoc is nothing

set rt_source = rtdoc.getFirstItem(“Body”)

call rt_target.appendRtItem(rt_source)

set rtdoc = view.getNextDocument(rtdoc)

Loop

call rt_target.compact()

set rtrange = rt_target.createRange()

call rtrange.findAndReplace(“…”, “…”, …)

call webdoc.save(true, false)

Print “[http…/0/” + webdoc.universalID + “]”

’ Call ws.editDocument(true, webdoc) ’ only use in notes

(Its an agent invoked from the web)

When i use this code then the document is assempled and shown on web, but the fields are not translated. If i use the bottom line (ws.editDocument…) then the fields are translated just fine ???

Should i refresh something ???

Thanks

Jacob Hansen

Subject: FindAndReplace not working on web? (RichText issue)

Jacob,

You’re not using the CreateNavigator and Update methods of NotesRichTextItem. See Designer Help. A NotesRichTextNavigator is needed in conjunction with a FindAndReplace action, and Update is needed to commit the changes when you want as opposed to letting Domino do it when it’s efficient.

Ken

Subject: RE: FindAndReplace not working on web? (RichText issue)

Hi Ken

Thank you for the reply, but it still wont work. In my original post i was only showing part of the code, im using a lot of code - too much to show here But it might help with a more detailed look into the program.

When im translating the fields i need to collect the replacement strings from the database im working in and i dont know in advance which strings to replace, so im using 3 functions to analyze, translate and insert the replacement strings.

Public Function RichTextLib_analyzeField(rtitem As NotesRichTextItem) As Long

RichTextLib_analyzeField = 0

On Error Resume Next



Dim rtnav As NotesRichTextNavigator, rtrange As NotesRichTextRange

Dim entry As ccEntry



Set mergeFields = New ccEntryArray()



Set rtnav = rtitem.createNavigator

If rtnav.findFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then

	Set rtrange = rtitem.createRange

	Do

		Call rtrange.setBegin(rtnav)

		Call getMergeFields(rtrange.textParagraph)

	Loop While rtnav.findNextElement(RTELEM_TYPE_TEXTPARAGRAPH)

End If



RichTextLib_analyzeField = mergeFields.count

End Function


Public Sub RichTextLib_insertMergeFields(rtitem As NotesRichTextItem)

Dim rtnav As NotesRichTextNavigator, rtrange As NotesRichTextRange

Dim entry As ccEntry

Dim searchStr As String, replaceStr As String



Set rtrange = rtitem.createRange



Set entry = mergeFields.getFirstEntry

Do While Not entry Is Nothing

	searchStr = "[" + entry.getValue("mergefield") + "]"

	replaceStr = entry.getValue("translated")

	Set rtnav = rtitem.createnavigator

	Call rtnav.findFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)

	Set rtrange = rtitem.CreateRange

	While rtrange.findAndReplace(searchStr, replaceStr, RT_FIND_CASEINSENSITIVE + RT_REPL_PRESERVECASE) > 0

		Call rtitem.update()		' Must update before looping

	Wend

	

	Set entry = mergeFields.getNextEntry

Loop

End Sub

The mergeFields object are simply an array consisting og entry objects.

The translation process is simple lotus script - just traversing the mergeFields array and translating all values.

I have just added Call rtitem.update() in the insertion funcion, but it is still not working - any ideas?

With regards

Jacob Hansen