Create Report Header in Email Message using Script

Hello,

I have an action button written in Lotus Script that loops through a bunch of documents in a view and creates an email message in the mail file of the person clicking the action. The action button formats the email message using documents and it’s formatted the way I need it.

The only other thing I would like to add is headings in the email message based on the begin date of the record in the view. So for example, my email report currently looks like this in the body field:

11/01/2006 blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

12/13/2006 blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

12/14/2006 blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

> blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

> blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

but I want it to look like this - notice I added the headings.

PAST EVENTS

11/01/2006 blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

UPCOMING EVENTS

12/13/2006 blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

12/14/2006 blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

DATE TO BE DETERMINED

> blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

> blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

It would seem that I need to use an If/Then/Elseif statement but what I can’t figure out is where to put the code and how to insert it so that the headers only print once no matter how many records fall under it.

Thank you in advance for any guidance!

Code - free typed so excuse typos. the code does work just need help with getting the headings in the email message : (

sub click(source as button)

declare variables to

establish rich text formatting

get mail file

get view

get view entry collection

etc

while not (doc is nothing)

rtpstyle.leftmargin = ruler_one_inch *1.5

rtpstyle.firstlineleftmargin = ruler_one_inch * 1.0

call rtitem.appendparagraphstyle(rtpstyle)

richstyle.bold = true

richstyle.fontsize = 12

richstyle.notesfont = rtitem.getnotesfont(“default sans serif”,true)

call rtitem.addnewline(2)

call rtitem.appendstyle(richstyle)

call rtitem.appendtext(doc.begindt(0))

call rtitem.appendtext(" ")

call rtitem.appendtext(doc.purpose(0))

call rtitem.appendtext(" ")

richstyle.bold = false

call rtitem.appendstyle(richstyle)

call rtitem.appendtext(doc.comment(0))

call rtitem.addnewline(1)

set doc = view.getnextdocument(doc)

wend

'open email with report

call maildoc.computewithform(false,false)

call ws.editdocument(true,maildoc

end sub

Subject: Create Report Header in Email Message using Script

Where are your “Headers” coming from? If they are generated from the documents you are looping through, create an array of headers and build it inside the loop. If not, build it outside the loop. Then write the headers wherever you need them in your body. You’ll have to add logic. If, as it seems, your header is simply a text string based on whether or not a date has passed, get todays date, outside the loop, and set a flag for each header (you can use an array) to False, and then check inside the loop to see if a flag is set (headerwritten(x) = false). Then write your data for that section in the if statement. At the end, set the variable headerXwritten to true. This will prevent it from running again. You would also increment x at this point so that the next iteration uses the correct array index.