Adding column to report adds column but no entries

I am trying to update one of my reports. I want to add a ‘Comments’ column to display the comments from my database’s journal entries.

Would anyone be kind enough to tell me why this code gives me my new column but doesn’t bring in the comments that are in the Comments field? I am not getting any error messages, just no information.

Sub Initialize

Dim s As New NotesSession

Dim db As NotesDatabase

Dim totals() As Integer

Dim models() As String

Dim families () As String

Dim comment () As String

Dim reasons() As String

Dim treasons() As Integer

Dim rc As Integer



Set db = s.CurrentDatabase



'/ build the list of models to search for

Print "build list of models to search for"



newDbFilename = "Products.nsf"

Set pDB = s.GetDatabase( db.Server, Left(db.filepath,Instr(1,db.filepath,db.filename)-1)+newDbFilename )

Set pView = pDb.GetView("(Products_RM)")

Set pDoc = pView.GetFirstDocument

Dim modelnumbers() As String

Dim productfamilies() As String

p = 0

While Not pDoc Is Nothing

	Redim Preserve modelnumbers(p)

	Redim Preserve productfamilies(p)

	modelnumbers(p) = pDoc.keymodelnumber(0)

	productfamilies(p) = pDoc.productfamily(0)

	p = p + 1

	Set pDoc = pView.GetNextDocument(pDoc)

Wend

p = p -1



'/ search for total occurances of models

Print "search for the total occurances of each model"

For n = 0 To p

	modelnumber = modelnumbers(n)

	productfamily = productfamilies(n)

	

	searchFormula$ = "FIELD modelnumber contains " & modelnumber

	Set collection = db.FTSearch( searchFormula$, 0 )

	

	Redim Preserve totals(n)

	Redim Preserve models(n)

	Redim Preserve families(n)

	totals(n) = collection.count

	models(n) = modelnumber

	families(n) = productfamily

	

	

Next





'/ Sort the results (by totals column)

Print "Sort the results"

Lower = 0

Upper = p



For i = 1 To upper - lower

	swapped = False

	For k = lower To upper -1

		

		If totals(k) < totals(k+1)  Then

			tmp = totals(k+1)

			tmp2 = models(k+1)

			totals(k+1) = totals(k)

			models(k+1) = models(k)

			totals(k) = tmp

			models(k) = tmp2

			swapped = True

		End If

	Next

	If Not swapped Then Exit For

Next



Redim Preserve reasons(0)

Redim Preserve treasons(0)

Redim Preserve families(0)

Redim Preserve comment(0)



Print "Write the results"	

'/ Write to Excel



Dim xlApp As Variant 

Dim xlBook As Variant

Dim xlsheet As Variant

Dim xlWB As Variant



Set xlApp = CreateObject("excel.application")

Set xlWB = xlApp.Workbooks

Set xlBook = xlApp.Workbooks.Add



Set xlSheet = xlBook.Worksheets(1)     



xlSheet.Cells(2,2 ).Value =  "CAREBase Report - Rubbermaid Calls Year-to-Date"

xlSheet.Cells(3,2).Value = "Calls"

xlSheet.Cells(3,3).Value = "Model"

xlSheet.Cells(3,4).Value = "Product Family"

xlSheet.Cells(3,5).Value = "Reason"

xlSheet.Cells(3,6).Value = "Comments"

rownum = 4

For j=0 To p

	

	xlSheet.Cells(rownum, 2).Value = totals(j)

	xlSheet.Cells(rownum, 3).Value = "'" & models(j)

	

	'/ get reasons

	rc = -1

	searchFormula$ = "FIELD modelnumber contains " & models(j)

	Set collection = db.FTSearch( searchFormula$, 0 )

	Set rDoc = collection.GetFirstDocument

	While Not rDoc Is Nothing

		Forall r In rDoc.Reasons

			foundAt = Arraygetindex( reasons(), r ,5 )

			If Isnull(foundAt) Then

				rc = rc + 1

				Redim Preserve reasons(rc)

				Redim Preserve treasons(rc)

				Redim Preserve comment(rc)

				comment(rc) = comments				

				reasons(rc) = r

				treasons(rc) = 1		

			Else

				treasons(foundAt) = treasons(foundAt) + 1

			End If

		End Forall

		

		Set rDoc = collection.GetNextDocument(rDoc)

	Wend

	

	

    '/ Sort the results (by rtotals column)

	Print "Sort the results"

	Lower = 0

	Upper = rc

	

	For i = 1 To upper - lower

		swapped = False

		For k = lower To upper -1

			

			If treasons(k) < treasons(k+1)  Then

				tmp = treasons(k+1)

				tmp2 = reasons(k+1)

				tmp3 = families(k+1)

				tmp4 = comment(k+1)

				treasons(k+1) = treasons(k)

				reasons(k+1) = reasons(k)

				families(k+1) = families(k)

				comment(k+1) = comment(k)

				treasons(k) = tmp

				reasons(k) = tmp2

				families(k) = tmp3

				comment(k) = tmp4

				swapped = True

			End If

		Next

		If Not swapped Then Exit For

	Next

	

	'/ write reasons

	For rb=0 To rc			

		rownum = rownum + 1

’ xlSheet.Cells(rownum, 4).Value = treasons(rb)

		xlSheet.Cells(rownum, 4).Value = families(rb)

		xlSheet.Cells(rownum, 5).Value = "'" & reasons(rb)

		xlSheet.Cells(rownum, 6).Value = comment(rb)

	Next

	

	Redim reasons(0)

	Redim treasons(0)

	

	

	rownum = rownum + 1

	

Next





xlApp.Visible = True



Set xlSheet = Nothing

Set xlBook = Nothing

End Sub

Thanks!

Lori

Subject: Adding column to report adds column but no entries

I’ll bet $5 that the Comments field is Rich Text. Right?

Subject: RE: Adding column to report adds column but no entries

Oh, I can recoup some of my Super Bowl pool $ if I don’t win…the field is a Text field, but not Rich Text. That was one of the first things I checked when it came up blank.

It is just a regular editable text field. When I check the document properties for the items that are displayed in my report, the Comments field is populated correctly.

Subject: Adding column to report adds column but no entries

Lori,

I balked at trying to figure out what your code is doing. Could you explain in a nutshell what you hope to accomplish with it? I’m sure there is a whole lot easier way to do this.

  • Matt

Subject: RE: Adding column to report adds column but no entries

To start with, I am new to LotusScript, so I am using an existing report’s code. I apologize that my coding is so bad.

I am trying to add a column to an existing report to bring the Comments from a journal form and then list the comments from the form in the column’s rows.

Subject: RE: Adding column to report adds column but no entries

I have had a read through the code and without being sure what the code is trying to do think that the offending line may be comment(rc) = comments

I can’t see that comments has been declared or set anywhere else in the code. If comments is a field on the document then you need to reference it with the notesdocument syntax

comment(rc) = rDoc.comments(0)

Forall r In rDoc.Reasons

foundAt = Arraygetindex( reasons(), r ,5 )

If Isnull(foundAt) Then

rc = rc + 1

Redim Preserve reasons(rc)

Redim Preserve treasons(rc)

Redim Preserve comment(rc)

comment(rc) = comments

reasons(rc) = r

treasons(rc) = 1

Subject: RE: Adding column to report adds column but no entries

That worked. I had added a line similar to that in another location in the coding, but received an error. I moved it to the same location as the ‘comment(rc) = comments’ and it added the information that I was looking for.

Thank you for your patience and your help!

Subject: RE: Adding column to report adds column but no entries

I have just one constructive critic about those redims in every loop.

I’ dont recommend it. Try not to use them in loops at least those you can fill otherwise

Subject: RE: Adding column to report adds column but no entries

I will make a second copy of this report code and try removing the redims. I am new to all of this and changing someone else’s code. It worked with those in, so I added more thinking more of what was working would work, too!

Thank you for the advice, I am always willing to learn and try more.

Lori

Subject: RE: Adding column to report adds column but no entries

As you are new to lotusscript here a couple of tips that you may not be aware of.

Adding Option Declare to the options section means that you have to declare a variable before you can reference it in your code. Otherwise you will get an error when you try to save it. This is a good way of trapping typing errors. In your code it would of complained that comments had not been declared. I would not add it to this as whoever wrote it does not appear to be a fan of declaring variables.

Take some time to familiarize yourself with the lotusscript debugger where you can run through code line by line and keep an eye on what variables are being set to as you are doing so.

dr Theory is correct in that Redim Preserve is inefficient especially when used in a loop. Where possible explicitly set the size of the array and then populate in the loop.

Your first loop as it stands is

Set pView = pDb.GetView(“(Products_RM)”)

Set pDoc = pView.GetFirstDocument

Dim modelnumbers() As String

Dim productfamilies() As String

p = 0

While Not pDoc Is Nothing

Redim Preserve modelnumbers(p)

Redim Preserve productfamilies(p)

modelnumbers(p) = pDoc.keymodelnumber(0)

productfamilies(p) = pDoc.productfamily(0)

p = p + 1

Set pDoc = pView.GetNextDocument(pDoc)

Wend

As you are populating the arrays with fields from every document in the view you can find out how large the arrays need to be. It can be rewritten as

Dim vc as notesviewentrycollection

Dim modelnumbers() As String

Dim productfamilies() As String

Set pView = pDb.GetView(“(Products_RM)”)

'get collection of all documents in the view

Set vc = pView.AllEntries

Set pDoc = pView.GetFirstDocument

'set the array size to the number of documents in the view

'minus one to allow for array indexing starting at zero

Redim modelnumbers(vc.Count - 1)

Redim productfamilies(vc.Count - 1)

p = 0

While Not pDoc Is Nothing

modelnumbers(p) = pDoc.keymodelnumber(0)

productfamilies(p) = pDoc.productfamily(0)

p = p + 1

Set pDoc = pView.GetNextDocument(pDoc)

Wend

Subject: Adding column to report adds column but no entries

Might be the comments field itself. ‘Computed for Display’, or maybe it’s Rich Text?

Subject: RE: Adding column to report adds column but no entries

It is just a regular editable text field. When I check the document properties for the items that are displayed in my report, the Comments field is populated correctly.

Subject: RE: Adding column to report adds column but no entries

Hmm… The next thing I would try is see what exactly the script is pulling.

I’d make a little script to grab a few selected entries from the journal, loop through and display the contents of the comments field with a msgbox. It’s crude, but if the results are blank, you know the issue is with the data in the field. If the comment shows up in the message box, you know your agent is getting the field value, and the problem is later in the code.

Subject: RE: Adding column to report adds column but no entries

Unfortunately, I am new to LotusScript, so this isn’t something I know how to do. Do you have any suggestions on how to get that information to pop?

Subject: RE: Adding column to report adds column but no entries

Make yourself an action button in your db’s view, put in the code, and then in the view run on a few documents you’ve selected & see if the data in the comments field shows up.

    Dim session As New NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim ws As New NotesUIWorkspace

Dim uiview As NotesUIView	

Dim tmpuiview As NotesUIView

Set db = session.CurrentDatabase	

Set dc =  db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

While Not(doc Is Nothing)

	Msgbox doc.comments(0)  'Replace with your field name if other than 'comments'

	Set doc = dc.GetNextDocument(doc)

Wend

'unselect the docs if desired

Set uiview = ws.CurrentView

Call uiview.DeselectAll

Print "Finished Processing " & dc.Count & " Documents"

~Erik

Subject: RE: Adding column to report adds column but no entries

Thank you, I added an action item to my report list and ran the agent and a box popped up with the comments that were listed in the item(s) that I selected each time I ran it.

So, I guess I will look into the writing section to see why it won’t take what I have and add it to the cells.

Thank you for helping me know for sure that I had at least gotten somewhere!

Subject: RE: Adding column to report adds column but no entries

I’m no LS guru either, so you might have a chat with the other poster, matt and he might be able to help you streamline your agent & minimize problems.

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/7ba6d1eb994971f98525726e0076f474?OpenDocument

Erik

Subject: RE: Adding column to report adds column but no entries

Matt’s last suggestion worked. Thanks for the help!

Lori

Subject: RE: Adding column to report adds column but no entries

Thanks, I will try that.

I was able to add a new column with other information and was happy to get that to work. When this one didn’t, my newly inflated LotusScript ego just went way down!