appendRTItem fails on last entry in array

I have a database that aggregates a number of document summaries into reports.

There is a shared action that creates the report.

The articles that the report is created from use RTItems to allow for formatting.

All this appears to work fine except for one minor glitch. The last document in the collection does not get put in the report. I know the looping structure sees the document because I get the client list and article title in the report. Those text items are appended right before the RTItem is.

The code is below. Any help is appreciated.

Thanks,

Shawn


Sub Click(Source As Button)

' CREATE SESSION VARIABLES

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace	

Dim database As  NotesDatabase

Dim documentCollection As NotesDocumentCollection

Dim billSummary As NotesDocument

Dim clientReport As NotesDocument

Dim reportBody As NotesRichTextItem

Dim summaryBody As NotesRichTextItem

Dim richStyle As NotesRichTextStyle

Dim clientField As Variant

' Dim requestedClient As String

' Dim client As String

Dim count As Integer



' SET INITIAL VALUES

Set database = session.CurrentDatabase

count = 1 ' INITIALIZE THE INTEGER

Set documentCollection = database.AllDocuments

Set clientReport = New NotesDocument(database)

Set reportBody = New NotesRichTextItem(clientReport, "fieReportBody")

Set richStyle = session.CreateRichTextStyle



' SET THE DOCUMENT FORM

Call clientReport.ReplaceItemValue( "Form", "frmReportSummary")



' GET THE FIRST DOCUMENT

Set billSummary = documentCollection.GetFirstDocument	



' COUNT STARTS AT 0

While(count <= documentCollection.Count)

	If billSummary.Form(0) = "frmBillSummary" Then

		' Get the summary text 

		Set summaryBody = billSummary.GetFirstItem("fieBillSummary")

		

		Set clientField = billSummary.GetFirstItem("fieClient")

		Forall summaryClient In clientField.Values

			reportbody.AppendText(summaryClient & ",")

		End Forall

		

		reportBody.AddNewline(1)

		

		' Create and Use Bold Style

		richStyle.Bold = True

		Call reportBody.AppendStyle(richStyle)

		

		' BUILD THE LINK TO THE BILL SUMMARY

		' Call reportBody.AppendDocLink(billSummary, "Bill Summary","link")

		Call reportBody.AppendDocLink(billSummary, "Bill Summary",billSummary.fieSummaryType(0) & billSummary.fieBillID(0))

		

		reportBody.AddNewline(2)	

		

		' APPEND THE REPORT BODY TO THE SUMMARY

		Call reportBody.AppendRTItem(summaryBody)

		

		' ADDED TO ENSURE FINAL RTItem was appended

		If count = documentCollection.Count Then

			Sleep 2

		End If

		

		reportBody.AddNewline(2)

		

		' Turn off Bold Style

		richStyle.Bold = False

		Call reportBody.AppendStyle(richStyle)

		

		reportBody.AddNewline(2)

		

	End If			

	

	Set billSummary = documentCollection.GetNextDocument(billSummary)

	count = count + 1		

	

Wend	







' SAVE THE REPORT AND OPEN IT FOR VIEWING

' Call clientReport.Save(True, False)

Call ws.EditDocument(False,clientReport,,,,)

End Sub

Subject: RE: appendRTItem fails on last entry in array

I have a similar code and the same bug. Some things from the last document in the collection get appended but not all. Never found out the reason why the last document is not appended right.

What I did as a quick fix is append the last document twice. Users know they have to discard the last truncated document. I know it’s not pretty but it’s the only solution I could come up with.

Hope it helps

Mael

Subject: Try using the Update method.

Subject: Re: Try using the Update method

DOH!

Many Thanks, Andre.

Subject: Alternatiev Approach

Sorry it took me so long to get back to this.

As another ‘workaround’, saving the document to the database (This was not a desired approach, for me at least) before displaying it in the workspace achieved what I wanted.

I had to go to the designer help and review the update method.

Thanks Andre, it’s clearly the right approach.

Shawn