Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I add a new line to a text field via LotusScript?

3,424 views
Skip to first unread message

Alastair Booker

unread,
Sep 19, 1996, 3:00:00 AM9/19/96
to

Hi,

I have a LotusScript macro that makes changes to a document. In amongst these
changes, I wish to add a value to the start of a text field, but on a new line
in that text field rather than just appended straight to what's already there.

I'm currently trying with this:

doc.Edit_History = "Change: " + Format$(Now(),"dd/mm/yy hh:mm:ss") + Chr$(13) +
Chr$(10) + doc.Edit_History(0)

But... the CR and LF get replaced by strange block characters after this has
been run. Also, any new lines already in the text field (placed there by
@NewLine from a formula-based macro) are changed to these characters...

Any ideas?

Thanks,

- Ali

(a...@squark.demon.co.uk)


Gregory Radcliff

unread,
Sep 20, 1996, 3:00:00 AM9/20/96
to

It turns out that neither Chr(10) or Chr(13) work when using LotusScript
extended class syntax to write to a text field. You either have to use
the NotesUIDocument FieldSetText method or change the text field to a
rich text field and use the NotesRichTextItem.AppendText method.

Using the NotesUIDocument Class, you could delimit your multivalues with
commas or semi-colons with the script, put it back as a string in the
field as a plain old string using the FieldSetText method in the
NotesUIDocument class, then have the field interpret the commas or
semi-colons as multi-value delimiters and display it with carraige
returns.

Hope this helps!

Greg Radcliff


Joe

unread,
Sep 20, 1996, 3:00:00 AM9/20/96
to

a...@squark.demon.co.uk (Alastair Booker) wrote:

>I have a LotusScript macro that makes changes to a document. In amongst these
>changes, I wish to add a value to the start of a text field, but on a new line
>in that text field rather than just appended straight to what's already there.

>I'm currently trying with this:

>doc.Edit_History = "Change: " + Format$(Now(),"dd/mm/yy hh:mm:ss") + Chr$(13) +
>Chr$(10) + doc.Edit_History(0)

>But... the CR and LF get replaced by strange block characters after this has
>been run. Also, any new lines already in the text field (placed there by
>@NewLine from a formula-based macro) are changed to these characters...

>Any ideas?

Ali,

That's a LotusScript bug (I think). I did find a workaround for the
frount end classes (i.e., Notesuidocument):

Call source.FieldAppendText("CalldownList_Log",Chr(10))

Joe


Joe

unread,
Sep 20, 1996, 3:00:00 AM9/20/96
to

Reposting article removed by rogue canceller.

Geoff Taylor

unread,
Sep 26, 1996, 3:00:00 AM9/26/96
to

Joe <jmc...@axionet.com> wrote in article
<R.51v7ds$o...@binky.axionet.com>...

> a...@squark.demon.co.uk (Alastair Booker) wrote:
>
> >I'm currently trying with this:
>
> >doc.Edit_History = "Change: " + Format$(Now(),"dd/mm/yy hh:mm:ss") +
Chr$(13) +
> >Chr$(10) + doc.Edit_History(0)
>
> >But... the CR and LF get replaced by strange block characters after this
has
> >been run. Also, any new lines already in the text field (placed there by

> >@NewLine from a formula-based macro) are changed to these characters...
>

> That's a LotusScript bug (I think). I did find a workaround for the
> frount end classes (i.e., Notesuidocument):
>
> Call source.FieldAppendText("CalldownList_Log",Chr(10))
>
> Joe

Another way (I think this may be the proper way, but I've never seen it
documented...) is to treat the field as an array, with each element of the
array being a line of text. So to put stuff on a new line, you add another
element to the array. For example, here's a LotusScript function I use to
append a string (passed as the only parameter) + user information to a
field. It's very easy:

'=============================================================
'=============================================================
'
' Sub : updateHistory_l
'
' Description
' -------------------
' This library-scope function is passed a string as its only parameter,
and it
' appends this string to the history field for audit-trail purposes.
Nothing too
' complicated here.
'
'=============================================================
'=============================================================
Public Sub updateHistory_l (message As String)
Dim oldHistory As Variant
Dim newHistory() As String
Dim counter As Integer
Dim newSize As Integer

'=============================================================
' Get existing history trail from document
'=============================================================

oldHistory = thisDocument_l.getItemValue ("documentHistory")

'=============================================================
' Set size of new history to one bigger than the existing history
'=============================================================

newSize = Ubound (oldHistory) + 1
Redim newHistory (newSize + 1)

'=============================================================
' Copy contents of old history into new history
'=============================================================

counter = 0
While counter < newSize
newHistory (counter) = oldHistory (counter)
counter = counter + 1
Wend

'=============================================================
' Added new details to history trail
' Copy new history to document
'=============================================================
newHistory (counter) = message + " by " + thisSession_l.CommonUserName
+ " on " + Date$

thisDocument_l.documentHistory = newHistory
End Sub

mer...@gmail.com

unread,
Oct 17, 2016, 5:14:46 PM10/17/16
to
On Thursday, September 19, 1996 at 1:00:00 AM UTC-6, Alastair Booker wrote:
> Hi,
>
> I have a LotusScript macro that makes changes to a document. In amongst these
> changes, I wish to add a value to the start of a text field, but on a new line
> in that text field rather than just appended straight to what's already there.
>
> I'm currently trying with this:
>
> doc.Edit_History = "Change: " + Format$(Now(),"dd/mm/yy hh:mm:ss") + Chr$(13) +
> Chr$(10) + doc.Edit_History(0)
>
> But... the CR and LF get replaced by strange block characters after this has
> been run. Also, any new lines already in the text field (placed there by
> @NewLine from a formula-based macro) are changed to these characters...
>
> Any ideas?
>
> Thanks,
>
> - Ali
>
> (a...@squark.demon.co.uk)

This answer comes after 10 year. Was doubtful whether to post it.. But someone else may be benefited.

The following code will insert a line before and after insertion text.

uidoc.InsertText Chr$(10) & insertionText & Chr$(10)

I tried different combinations before arriving at this.

Thank you
Mert

Kirk Stoner

unread,
May 22, 2023, 2:35:06 PM5/22/23
to
As @Alastair Booker is using the NotesDocument class (not NotesUiDocument), there are two ways to accomplish this:
1. Already stated: use of an Array but this is a bit simpler:
Dim newHistory(0) As String
newHistory(0) = "My new value to add to the end"
Call doc.ReplaceItemValue("Edit_History", ArrayAppend(doc.GetItemValue("Edit_History"), newHistory))
2. Use the NoteItem Class:
Dim item As NotesItem
Set item = doc,GetFirstItem("Edit_History")
Call item.AppendToTestList("My new value to add to the end")

Method #1 provides the ability to "PrePend" values to the top of the list by reversing the order in ArrayAppend:
Dim newHistory(0) As String
newHistory(0) = "My new value to add to the end"
Call doc.ReplaceItemValue("Edit_History", ArrayAppend(newHistory, doc.GetItemValue("Edit_History")))

Kirk

Kirk Stoner

unread,
May 22, 2023, 2:39:04 PM5/22/23
to
Auto-misspell correction for solution #2:
Call item.AppendToTestList(...) -> Call item.AppendToTextList(...)
Plain old typo correction:
doc,GetFirstItem -> doc.GetFirstItem
0 new messages