Lotus Notes Agent creates a memo and appends richtext to richtext to plain text for memo

1.  User opens a new request and adds text to a richtext description field and submits request.
2.  Mail routing occurs with the description field in the body of the memo.
3.  On doc submission, an agent runs to create memo and append richtext.
4.  The first line is predetermined plain text.
5.  The next lines include the richtext description field entered by user.
6.  The last line appends more predetermined plain text to that richtext.

Problem is formatting when user adds bullets or numbering.  The memo displays the 1st and last text lines ok, but places the richtext bulleted text left of the screen as follows:

          line 1: Description plain text:

          This is the richtext user adds to description field with bullests.


1.  kljasf;jas;d - bullets or numbering formats left of screen.
2.  adl;jdflasjf;

              last line: Please click link to review your request:

Dim rtitem As NotesRichTextItem
	Dim item As NotesItem
'	Dim rtitem2 As NotesItem
	Dim rtitem2 As NotesRichTextItem   


                Set richstyle = session.CreateRichTextStyle
		Set rtitem = New NotesRichTextItem( newDoc , "Body" )
		richstyle.NotesColor = COLOR_DARK_BLUE
		richStyle.FontSize = 10
		richStyle.Bold = True
		Call rtitem.AppendStyle(richstyle)
		Call rtitem.AddNewLine( 1 )
		richstyle.NotesColor = COLOR_DARK_MAGENTA
		richStyle.Italic = True
		Call rtitem.AppendStyle(richstyle)
		Call rtitem.AppendText(" line 1: Description plain text")
		Call rtitem.AddNewLine( 2 )
'		Call rtitem.AddTab( 1 )
		richstyle.NotesColor = COLOR_BLACK
		richStyle.FontSize = 9
		richStyle.Bold = True
		richStyle.Italic = False
		Call rtitem.AppendStyle(richstyle)
		Set rtitem2 = doc.getfirstitem("Description") 
		Call rtitem.AppendRTItem(rtitem2)
		richStyle.Italic = False
		Call rtitem.AddNewLine(2)
		richstyle.NotesColor = COLOR_DARK_BLUE
		richStyle.FontSize = 10
		richStyle.Bold = True
		Call rtitem.AppendStyle(richstyle)
		Call rtitem.AddNewLine(2)
		Call rtitem.AppendText("last line: Please click link to review your request:")
		Call rtitem.AppendDocLink( docnew , db.Title)   
		newDoc.Subject = ("Action required" )
		Call rtitem.AddNewLine(1)
		newDoc.SendTo = doc.dev
			newDoc.CopyTo = doc.plan
				newDoc.Send( False )

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

25 pts?!?

Look at RichTextParagraphStyle class.
Properties LeftMargin and RightMargin.
Ignore the first line of my post.
This is how it works:
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim rt As NotesRichTextItem
Dim rts As NotesrichTextParagraphStyle

Set db = s.Currentdatabase
Set doc = New NotesDocument(db)
Call doc.AppendItemValue("From", s.Username)
Call doc.AppendItemValue("Subject", "Test paragraph style")

Set rts = s.CreateRichTextParagraphStyle
Set rt = New NotesRichTextItem(doc, "Body")
rts.LeftMargin = 2 * 567    '2cm

Call rt.AppendParagraphStyle(rts)
Call rt.AppendText("New indent starts here")
Call rt.AddNewLine(1)
Call rt.AppendText ("what happens here")

Call doc.Save(True, False)

Open in new window

KTTKTTAuthor Commented:

Thanks for the example!

after the subject line, I need to append text to the Body.
2nd need to append richtext Description field to that,
3rd need to append text to it.

trying to get the order right.  Do I use the rts.leftmargin setting after the 1st line of text before I append the richtext description field>   At the end of say line 19 after the text, do i do something like this:

Set rt = New NotesRichTextItem(doc, "Description")
Call rt.AppendParagraphStyle(rts)

then go back to appending text with Call rt.AppendText("this is text")

Style is always set before entering the content, that you want the style to apply to.
I'm not sure you'll be able to do this like this, since rich text contents have its own format properties, so when you append the second RTF I'm not sure whether the new style will apply to its contents.

I think that you can even try this manually to figure out the right way to do it, open two documents with RTFs, go to the end of first RTF, change indentation and then paste the contents of second RTF.
Is the contents of second rtf indented or it transferred its indentation?

If you don't care for font formatting, you can get the value of second RTF by using getFormattedText or getUnformattedText methods of NotesRichTextItem class.

Also, you can try it with:
    NotesRichTextRange = NotesRichTextNavigator.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)

to get NotesRichTextRange, which has a method:
    notesRichTextRange.SetStyle( NotesRichTextStyle style )

Bellow is example of agent that uses the default range to set the size of all elements in an item.

Look for more detail in Designer help.
Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim rtrange As NotesRichTextRange
Dim rtstyle As NotesRichTextStyle

Sub Initialize
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  If dc.Count = 0 Then
    Messagebox "No document selected",, "No doc"
    Exit Sub
  End If
  Set doc = dc.GetFirstDocument
  Set body = doc.GetFirstItem("Body")
  Set rtrange = body.CreateRange
  Set rtstyle = session.CreateRichTextStyle
  fontSizeString$ = Inputbox$("Size 8 - 24", "Font size")
  If Not Isnumeric(fontSizeString$) Then
    Messagebox "Size must be an integer 8 - 24",, _
    "Not numeric"
    Exit Sub
  End If
  fontSize% = Cint(fontSizeString$)
  If fontSize% < 8 Then fontSize% = 8
  If fontSize% > 24 Then fontSize% = 24
  rtstyle.FontSize = fontSize%
  Call rtrange.SetStyle(rtstyle)
  Call doc.Save(True, True)
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.