Fields disappear from documents

Hello,

The problem we face has been previously discussed in this forum under the same Subject as above.

But this time I believe we have found the reason why the problem occurs.

The problem: Some users create Lotus documents, and then using a button(lotusscript) they create/edit/read a word document that is attached in a RTF in the lotus document.

At some point (several days later or even the same day) the Lotus Notes document, looses almost all of its fields, as if someone runs an agent that calls the Call doc.Remove(fieldname).

We don’t do that! But we do something else. When the user finishes editing the Word document the script removes the contents of the Rich Text field and re-attaches the document back to it.

Here is the code:

If currdoc.Hasitem( “myRTField”) Then

Set rtitem = currdoc.GetFirstItem( "myRTField" )

If (rtitem.Type = RICHTEXT) Then

    If Not Isempty(rtitem.EmbeddedObjects) Then

Forall x In rtitem.EmbeddedObjects

					    If ( x.Type = EMBED_ATTACHMENT ) Then

          Call x.Remove

               End If

End Forall

    End If



    If (Not DocUniversalID = "") Then

          Set object = rtitem.EmbedObject(EMBED_ATTACHMENT, "",path,"")

          Call currdoc.save(True, True)	

    End If

			

End If	

End If

Our belief is that the Forall x In rtitem.EmbeddedObjects is getting a handle somehow on the document itself and the Remove takes place on the individual fields and not on the Rich Text field.

The reason why we believe this is the cause of the problem, is because everytime we loose the fields of from a document the RTfield holds two attachments where it should only have one. We re-attach in the last IF statement above.

Please do give me your thoughts why Lotus Notes behaves like this and if you agree that this might be the reason we loose the fields.

Thanks.

Subject: RE: Fields disappear from documents

The circumstances certainly seem a little suspicious, but I don’t understand why you’re asking here instead of trying it out yourself.

One thing I notice about your algorithm is that you’re iterating through a collection and deleting things from the collection as you go along.

Maybe this is what’s happening: if there’s only one thing there, the loop might be thinking it’s done after the first iteration. But if there are two, then on the second iteration the loop tries to fetch the second member of the collection – but there is no second member anymore. So perhaps it’s fetching something else that’s after it in memory.

You might have better luck if you copied the EmbeddedObjects into a variable, then used a For loop instead of Forall – you might also want to go through the array elements backwards.

Incidentally, I tried coding it the way you did and it didn’t crunch the document, but I’m using version 8.5, and it’s possible it’s been fixed since 6.5.6.

Subject: RE: Fields disappear from documents

This code very rarely malfunctions. Only 1% of the documents created by the users have this problem and in our development environment it has never occurred. So it could be due to a combination of that script with some settings that the users individually have that we could not spot.

We will try to re-code it as you suggest and perhaps consider an upgrate to R8 very soon.

Thanks.