Agent - appending value to report form

I have posted this issues. I modify my lotusscript. I like to append item value to create a report…see my code below:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim mailDoc As NotesDocument, bodyDoc As NotesDocument

Dim rtitem As NotesRichTextItem

Dim result As Variant

Dim j As Integer



query$ = Inputbox("Enter string to search for", "Query")

Set dc = db.FTSearch(query$,0)

'Set doc = dc.GetFirstDocument

Set dc = db.AllDocuments

For j% = 1 To dc.Count

	Set doc = dc.GetNthDocument(j%)

	Messagebox(dc.count)

	If dc.count >0 Then

		doc.Form ="MNFR"

		doc.EmpMeetDate = doc.EmpMeetDate

		doc.Department = doc.Department

		doc.FdQuestion = doc.FdQuestion

		doc.Answer = doc.Answer

		doc.FdQuestion1= doc.FdQuestion1	

		doc.Answer1= doc.Answer1

		doc.FdQuestion2= doc.FdQuestion2	

		doc.Answer2= doc.Answer2

		doc.FdQuestion3 = doc.FdQuestion3

		doc.Answer3= doc.Answer3

	Else

		doc.Answer=doc.Answer(0) & Chr(13) & doc.Answer(0)

		doc.Answer1=doc.Answer1(0) & Chr(13) & doc.Answer1(0)

		doc.Answer2=doc.Answer2(0) & Chr(13) & doc.Answer2(0)

		doc.Answer3=doc.Answer3(0) & Chr(13) & doc.Answer3(0)

	End If

Next

doc.Form ="MNFR"

Set mailDoc = New NotesDocument(db)     

Set rtitem = New NotesRichTextItem (maildoc, "Body")

Call rtitem.AddNewLine(1)          

Call rtitem.appendtext ("Please review Report:  "+doc.EmpMeetDate(0))

Call rtitem.AddNewLine(2)              

success = doc.RenderToRTItem( rtitem )   



mailDoc.Form = "Memo"

mailDoc.Subject = "This is a test"

mailDoc.SendTo = session.commonuser

Call mailDoc.Save( True, True )  

Call mailDoc.send(False)  

please advise

amp

Subject: RE: Agent - appending value to report form

I see your code. Did you have a question or problem about the code, or are you just showing it to us? If you do have a question, please supply more details, including what it is supposed to do, what it’s doing instead of what it’s supposed to.

If there’s some information missing from the email, try calling Update method either just before, or just after, RenderToRTItem.

Subject: RE: Agent - appending value to report form

I have posted a full detail yesterday.

What I am trying to do is to create a report using key value of empmeetdate and dept and search for all the documents and append value to that report… so, all answers field should append the value and collect in one report.

thanks for your response

amp

Subject: RE: Agent - appending value to report form

I have posted a full detail yesterday.

But I can’t find it.

You have some basic logic errors in your code. It seems like you are trying to build a report in the variable doc, but each time through the loop the value of doc is different, so you are not accumulating information.

The redbook Domino Designer 6 A Developer’s Handbook contains a chapter about programming rich text, which includes examples of creating reports of the type you are trying to create.

Subject: RE: Agent - appending value to report form

I am not using richtext. Here my code that i modify. The code is bring no values. Const NotesMacro$ = | @Text(@DBColumn(“” : “” ; “” : “” ; “MgReport” ;1)) |

Dim session As New NotesSession

Dim db As NotesDatabase

Set db=session.currentdatabase

Dim workspace As New NotesUIWorkspace

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim mailDoc As NotesDocument, bodyDoc As NotesDocument

Dim rtitem As NotesRichTextItem

Dim result As Variant

Dim j As Integer

result = Evaluate(NotesMacro$,doc)

query$ = workspace.Prompt (PROMPT_OKCANCELLIST,"Select a Date", "Select one Employee Meeting Date from below list.", result, result)

'dim dateTime As New NotesDateTime(Cstr(Datenumber(2000, 5, 1)))

'searchFormula$ = {Form = "MgFeedback" & EmpMeetDate = @Today }

Set dc = db.Search(query$,dateTime,0)

Set doc = dc.GetFirstDocument



For j = 1 To dc.Count

	'Set doc = dc.GetNthDocument(j%)

	

	If dc.count >0 Then

		doc.Form ="MNFR"

		doc.EmpMeetDate = doc.EmpMeetDate

		doc.Department = doc.Department

		doc.FdQuestion = doc.FdQuestion

		doc.Answer = doc.Answer

		doc.FdQuestion1= doc.FdQuestion1	

		doc.Answer1= doc.Answer1

		doc.FdQuestion2= doc.FdQuestion2	

		doc.Answer2= doc.Answer2

		doc.FdQuestion3 = doc.FdQuestion3

		doc.Answer3= doc.Answer3

	Else

		doc.Answer=doc.Answer(0) & Chr(13) & doc.Answer(0)

		doc.Answer1=doc.Answer1(0) & Chr(13) & doc.Answer1(0)

		doc.Answer2=doc.Answer2(0) & Chr(13) & doc.Answer2(0)

		doc.Answer3=doc.Answer3(0) & Chr(13) & doc.Answer3(0)

	End If

Next

doc.Form ="MNFR"

Set mailDoc = New NotesDocument(db)     

Set rtitem = New NotesRichTextItem (maildoc, "Body")

Call rtitem.AddNewLine(1)          

Call rtitem.appendtext ("Please review Management Feedback Report:  "+doc.EmpMeetDate(0))

Call rtitem.AddNewLine(2)              

success = doc.RenderToRTItem( rtitem )   



mailDoc.Form = "Memo"

mailDoc.Subject = "THIS IS A TEST"

mailDoc.SendTo = session.commeruser

Call mailDoc.Save( True, True )  

Call mailDoc.send(False)  

Pleaseeee advise

amp

Subject: RE: Agent - appending value to report form

I’ve added some remarks in your code in this color, but there are more things you need to do. I see at least one serious error here that I told you about in my last message and you did not correct, so it seems you are not “getting it”. I think perhaps you do not understand LotusScript well enough to do this project. It might be best to find someone local who can help you.

… query$ = workspace.Prompt (PROMPT_OKCANCELLIST,“Select a Date”, “Select one Employee Meeting Date from below list.”, result, result)

… Set dc = db.Search(query$,dateTime,0)

A few things here:

If you don’t want a start date, you can say Nothing here instead of dateTime. Nothing is faster.

You are using the Search method, which requires a macro formula as input, but the user’s input is not a macro formula, just a date.

The Search method is not very efficient, especially if there are many documents in the database. If ou have a view sorted by date, GetAllDocumentsByKey will very quickly return the set of documents you need.

Set doc = dc.GetFirstDocument

Set docReport = db.CreateDocument()

You are trying to use the variable doc for two different things. You cannot use it for these two different things. You need one variable to be “the current document” that you’re examining, and another variable to store the lines of your report. Do not modify “the current document” doc, because you’re just going to throw that value away when you get the next document.

Dim docNext as NotesDocument

For j = 1 To dc.Count

	'Set doc = dc.GetNthDocument(j%)

	

	If dc.count >0 j = 1 Then

Because of the For loop above, you never get here unless dc.Count > 0.

I think, anyway, that you intended to test whether j=1.

		doc.Form ="MNFR"

		docReport.EmpMeetDate = doc.EmpMeetDate

		docReport.Department = doc.Department

		docReport.FdQuestion = doc.FdQuestion

		docReport.Answer = doc.Answer

		docReport.FdQuestion1= doc.FdQuestion1	

		docReport.Answer1= doc.Answer1

		docReport.FdQuestion2= doc.FdQuestion2	

		docReport.Answer2= doc.Answer2

		docReport.FdQuestion3 = doc.FdQuestion3

		docReport.Answer3= doc.Answer3

	Else

		docReport.Answer=docReport.Answer(0) & Chr(13) & doc.Answer(0)

		docReport.Answer1=docReport.Answer1(0) & Chr(13) & doc.Answer1(0)

		docReport.Answer2=docReport.Answer2(0) & Chr(13) & doc.Answer2(0)

		docReport.Answer3=docReport.Answer3(0) & Chr(13) & doc.Answer3(0)



	End If

 	Set docNext = dc.GetNextDocument(doc)

	Delete doc

	Set doc = docNext

Next

docReport.Form ="MNFR"

Set mailDoc = New NotesDocument(db)     

Set rtitem = New NotesRichTextItem (maildoc, "Body")

Call rtitem.AddNewLine(1)          

Call rtitem.appendtext ("Please review Management Feedback Report:  "+doc.EmpMeetDate(0))

Call rtitem.AddNewLine(2)              

success = docReport.RenderToRTItem( rtitem )   

Please think about what happens here if dc.Count = 0. There is not a report to review. Do you want to send an email that says, “Please review this report” and then there is no report? Or do you want to tell the user who is running this agent, and ask them to choose a different date? It might be that the design of your application is such that if the data is on the list to select, there is always at least one matching document. But I can’t tell that for sure from this code.

mailDoc.Form = "Memo"

mailDoc.Subject = "THIS IS A TEST"

mailDoc.SendTo = session.commeruser

Since there is no such property as commeruser, and since you declared session, this tells me that this is not your actual code. That’s annoying. I’ve been wasting my time reviewing code which is not the same code you are using. Is it really easier for you to retype the whole thing rather than copy and paste?

Call mailDoc.Save( True, True )  

It is not necessary to save the document before sending. If you want to save a copy, fine.

Call mailDoc.send(False)