• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1443
  • Last Modified:

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

  • 4
1 Solution
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now