Domino 9 und frühere Versionen > ND8: Entwicklung
Richttextitem wird zusätzlich angelegt
marschul:
Und wieder etwas dazugelernt: Peter hat Recht. Bei RTitems gleichen Namens liefert .getfirstitem tatsächlich ein Objekt zurück, welches den Inhalt all dieser Felder enthält (bei z.B. $File ist das anders).
Damit sind die Sorgenfalten erst einmal beseitigt, wobei nach wie vor nicht klar ist, wodurch das 2. Feld entsteht ???
Hatte zwischenzeitlich in Verdacht, dass aufgrund der Schleife mit dem wiederholten Set oBemerkungNew = .getfirstitem("Bemerkung") u.U. Nothing herauskommt und deshalb ein weiteres Feld explizit angelegt wird, aber das konnte schnell getestet werden:
--- Code: ---Sub Click(Source As Button)
Dim oWS As New NotesUIWorkspace
Dim oCurrDoc As NotesDocument
Dim oRTitem As NotesRichTextItem
Set oCurrDoc = oWS.CurrentDocument.Document
Set oRTitem = oCurrDoc.GetFirstItem("Body")
If oRTitem Is Nothing Then Set oRTitem = oCurrDoc.CreateRichTextItem("Body")
oRTitem.AppendText "Muff1"
Set oRTitem = oCurrDoc.GetFirstItem("Body") ' -> Test, ob das soeben angelegte RTitem zurückgegeben wird
If oRTitem Is Nothing Then
Set oRTitem = oCurrDoc.CreateRichTextItem("Body")
End If
oRTitem.AppendText "Muff2"
oCurrDoc.Save True, False
End Sub
--- Ende Code ---
In das 2. CreateRichTextItem gelangt das Programm NICHT.
Zu provizieren, dass 2 Felder angelegt werden, war übrigens auch nicht so einfach, wie gedacht, ein zweites Create meckert Notes nämlich an. Hab's dann so gemacht, dass ich das UIDoc zuerst speichere (dieses enthält laut Maske ein Body-Feld) und anschließend noch ein Body-Feld im Backend-Doc erstellt und dieses auch gespeichert. Ist Pfui, aber war ja auch nur meine Spielwiesen-DB ;)
TRO:
das ist ein bekanntes Problem, ein
rtitem.Compact
(und eventuell vorher ein rtitem.Update, siehe Designer-Hilfe zu Compact)
hilft da.
Aus der Knowledgebase:
The Document Properties on a Notes document shows two entries for the same Rich Text field (RTF). This issue occurs on documents that use LotusScript to create or update the Rich Text field. Two or more Rich Text fields will appear in the Document Properties until the document is edited and saved in the front-end or user interface. Workaround: In Notes/Domino 6.0 the new Compact method (of NotesRichTextItem class) can be used to remove the extra items.
Content
This issue occurs on documents that use LotusScript to create or update the Rich Text field. Two or more Rich Text fields will appear in the Document Properties until the document is edited and saved in the front-end or user interface. This issue was reported to Quality Engineering and it was determined that Notes is working as designed.
This issue has been observed with the following methods in Notes 4.5x and later (with the exception noted):
AddNewLine
AppendText
CreateRichTextItem - Note: This method causes the issue in only Notes 4.5x/4.6.x.
EmbedObject - Note: This method does not cause the issue in Notes 6.x or 7.x.
AddNewLine example:
Set rtitem=doc.getfirstitem("RTF")
Call rtitem.addnewline(1)
AppendText example:
Set rtitem=doc.getfirstitem("RTF")
Call rtitem.appendtext("add some text")
CreateRichTextItem example:
Call doc.RemoveItem("RTF")
Set rtitem = doc.CreateRichTextItem("RTF")
Call rtitem.AppendText(value)
EmbedObject example:
Set rtitem = New NotesRichTextItem( doc, "Body" )
Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", "c:\work\test.txt")
Note: You may observe that using the New method with the NotesRichTextItem class will produce only one field entry. This is actually undesirable as the Item is not properly added to the Document object. See the related document noted below.
Example:
Call doc.RemoveItem("RTF")
Dim rtitem as New NotesRichTextItem(doc, "RTF")
Call rtitem.AppendText(value)
Workaround:
In Notes/Domino 6.0 the LotusScript Compact method was added to the NotesRichTextItem class. The method provides the means to compact unused space within Rich Text fields, and during the process unnecessary items of the object are removed. This method can therefore be used to work around the issue described in this document. Once updates to the NotesRichTextItem are complete the Compact method can then be applied.
Example:
Set rtitem=doc.getfirstitem("RTF")
Call rtitem.appendtext("add some text")
Call rtitem.compact
Note: When using the Compact method it is best to call it after all updates to the NotesRichTextItem have been made, as it will effect the positions of any NotesRichTextNavigator objects, relating to the NotesRichTextItem object, that the code contains.
Supporting Information
In Notes/Domino 6.5 the JavaScript Compact method was added to the RichTextItem class.
marschul:
--- Zitat von: TRO am 25.05.11 - 16:55:11 ---rtitem.Compact
--- Ende Zitat ---
... ist ein guter Hinweis - Danke! Probier ich morgen früh gleich aus, Züge warten leider nicht... Schönen Abend!
marschul:
rtitem.compact klappt hervorragend :)
Es lässt sich also festhalten, dass ein über das Frontend gespeichertes RT-Item bei anschließender Bearbeitung im Backend mehrfach im Dokument existiert. Dazu genügt (konnte ich gerade reproduzieren) ein .appendtext, so wie im Beitrag von TRO beschrieben. Wird zum Schluss ein rtitem.compact vor dem Speichern des Backend-Dokuments durchgeführt, exisitert anschließend nur noch ein RT-Item - gem. Bernhards Beitrag natürlich abhängig von der Größe des Inhalts ;)
Vielen Dank für Eure Unterstützung!
Navigation
[0] Themen-Index
[*] Vorherige Sete
Zur normalen Ansicht wechseln