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
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
>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
> >@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