NotesNames in LotusScript

Just wanted to show how easy creating names, authors, and readers fields can be in LotusScript?

As always there are different ways to accomplish that. Here’s two of them.

1) Use New NotesItem:
Set item = new NotesItem(“SendTo”, sendToArray,NAMES) ‘ For other type use the SpecialType parameter with AUTHORS or READERS instead of NAMES depending on what you want to create.

This is useful if you want to do something more with the field/item.
Eg. Change some properties.

2) Using ReplaceItemValue
set item = doc.replaceItemValue(“SendTo”,sendToArray)

This will only create a text field item. We need to change it to an Names item.
item.isNames = true

This can be shortened since ReplaceItemValue returns a notes item:
doc.replaceItemValue(“SendTo”,sendToArray) .isNames = True

If you want it to be readers field or authors field do this.

doc.replaceItemValue(“SendTo”,sendToArray) .isReaders = True

doc.replaceItemValue(“SendTo”,sendToArray) .isAuthors = True

Personally I tend to use the shortened version since I find it easier to read. That is if I do not need the NotesItem further down in the code.

It saves me a dummy variable which may not be using further down in the code.
I do not like to set variables which are never used.

It’s like in a movie where you get to see a shotgun in the beginning of the film. You then sort of expect it to be used before the end.


One line @ReplaceSubString for lotusscript

[Update: Read the comments for a better solution with short strings (unverified)!]

Had this problem removing single characters in a string. I don’t like the idea to use strRight() and strLeft() since they can only handle a single entry of the search string.

There are a lot of different solution for this. I have also made my own lotusscript function for @replaceSubString, as every one else. All to complex since Release 6.

Some split and join will do the trick. This is my one liner:
resultStr = join( split( sourceStr, fromStr ), toStr )

The replace is case sensitive.

Example replacing word:
ReplaceSubString Example1

Button code:

Dim ui As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = ui.CurrentDocument
Set doc = uidoc.Document
doc.result = Join(Split(doc.text(0),doc.Replace(0)),doc.replacewith(0))

Example removing character:
ReplaceSubString Example2

Or make a function out of it to make it more readable:

Function replaceSubString(sourceStr As String, fromStr As String, toString As String) As String

replaceSubString = Join(Split(sourceStr,fromStr),toString)

End Function