@Uniquing a multivalue field with script

I’ve never been overly strong on handling multivalue fields with script.

I need to grab the contents of a multivalue field called “EventsInvitedTo”, tack on the most recent event, and save the new value back to the doc. This is working great.

Now, I’d like to @Unique what I’m saving. How do I add that to what I have so far. Here is what I have so far, with no attempt to @Unique yet.

myEvent = “LatestEvent”

Set MLSEventsCurrent = MLSDoc.GetFirstItem(“EventsInvitedTo”)

Call MLSEventsCurrent.AppendToTextList(MyEvent)

Call MLSDoc.Save( True, False )

Subject: @Uniquing a multivalue field with script

Take a look at the LS Function ArrayUnique in the help. Take the values from the field using NotesItem.Values, apply unique and then reassign the values…

Subject: RE: @Uniquing a multivalue field with script

Are there any samples or examples of how to process a multivalue field in script? I couldn’t find any in help. I can’t imagine that I’m the first to wonder.

Subject: RE: @Uniquing a multivalue field with script

Refer to the following:-

ArrayUnique function

Removes duplicate elements from an Array.

Note This function is new with Domino Release 6.

Syntax

ArrayUnique(sourceArray [,compMethod ])

Elements

sourceArray

Array of any type.

compMethod

Optional Integer specifying the type of comparison to use when searching for the delimiter, if the elements are strings.

Number Comparison Mode

0 case sensitive, pitch sensitive

1 case insensitive, pitch sensitive

4 case sensitive, pitch insensitive

5 case insensitive, pitch insensitive

If you omit compMethod, the default comparison mode is the mode set by the Option Compare statement for this module. If there is no statement for the module, the default is case sensitive and pitch sensitive.

Return value

Returns an array with duplicates removed. For any elements of the array which compare equal, the first occurrence is copied into the result array.

Usage

Elements in a variant array will only compare equal if they are of the same type. The variant array can’t contain classes or objects.

Array elements that contain the null value will match other null values.

Array elements that are empty will match with other elements that are empty.

Error handling

ArrayUnique throws a Run-time Type mismatch if:

the first parameter is not an array

a list is passed instead of an array

the array passed in has not been properly initialized

the array is of classes

the array is of NotesDocuments

the array contains an array as an element

the array contains nothing as an element

ArrayUnique throws a run-time Wrong Number of Dimensions error if the array is not one-dimensional.

Subject: RE: @Uniquing a multivalue field with script

never mind, I’ll just do @Unique in the translation of the field and have the script do a

doc.ComputeWithForm(True, false)

I just wanted to @unique a field, not launch something into space :}

Subject: huh? ArrayUnique function launching something into space?

If only putting something in space was this easy.

The example in the Domino Designer help, looks pretty basic to me??

'Declare array of variants

Dim myTestarr(4) as variant

myTestArr(0) = “abc DEF Ghi”
myTestArr(1) = “ABC def gHi”
myTestArr(2) = “abc DEF Ghi”
myTestArr(3) = “ABC def gHi”
myTestArr(4) = “abc DEF Ghi”

Sub Initialize
Dim resultArr as variant
Dim count as integer

’ use Comparison Method = 0 (case sensitive, pitch sensitive)

resultArr = arrayunique(myTestArr,0)
for count = lbound(resultArr) To ubound(resultArr)
Print resultArr(count)
next count
End Sub

'Output:
'abc DEF Ghi
'ABC def gHi

Subject: RE: huh? ArrayUnique function launching something into space?

sure, if i want to work with text that has nothing to do with a pre-existing multivalue field, and if i don’t wanna save that text anywhere.

Subject: RE: huh? ArrayUnique function launching something into space?

It’s just this simple:

doc.Fieldname = ArrayUnique(doc.Fieldname)

We’ll assume that the rest of the niceties have already been addressed (getting a handle on the doc and so forth). Using the default comparison method is probably what you want if @Unique would have done the job, and relying on the implicitly created temporary Variant array that results from getting doc.Fieldname will do the trick without adding any extra keystrokes.

Subject: RE: huh? ArrayUnique function launching something into space?

To assign a multivalued field from an array, is just like assigning any field from any other kind of value. For instance, you can use ReplaceItemValue method with the array as the value argument:

doc.ReplaceItemValue “fieldname”, myArray

As you can see, it’s not rocket science, and this is covered in the help, as well as in the developer training courses.