Problem solve Get help with specific problems with your technologies, process and projects.

How can I remove one element in a field without removing all values and replacing them?

I want to remove a element from a multi-valued field (specifically, the third element).

I want to remove element "white" from the field. How can this be done in script without removing all of the values and replacing them?
Either use Evaluate (inefficient, and the formula can be complex) or write LotusScript code to remove the unwanted item from the array, then assign the field from the array.

As with any other task that's more complex than you might like, you can make it easier on yourself by modularizing the code into reusable bits. For example, you could use the following routine:

Sub RemoveElementFromField
(doc As NotesDocument, Byval 
fieldname As String, Byval index As Integer) 
        Dim value As Variant, i As Integer 
        value = doc.GetItemValue(fieldname) 
        If index > 0 And index 
<= Ubound(value) Then 
                If Ubound(value) = 0 Then 
ReplaceItemValue fieldname, "" 
                        Redim Preserve 
value(0 To Ubound(value) - 1) 
                        For i = index To Ubound(value)-1 
                                value(i) = value(i+1) 
fieldname, value 
                End If 
        End If 
End Sub
Once you have this, you can remove the value you wanted from the array using a statement such as:
RemoveValueFromField doc, "Colors", 2
If you wanted to be more general about it, you could write a routine to manipulate arrays:
Function ArrayRemove(arr As Variant, Byval ind As Integer) As Variant ' Returns the array with the element at index 'ind' taken out.
then (alternately) you could reassign t he field using the statement:
doc.Colors = ArrayRemove(myfield, 2)
Also, you could write a function to scan the array for the value you wanted to remove, for cases where you don't know the index:
Function SearchAndDestroy(arr As Variant, 
value As Variant, Byval compMethod As 
        Dim pos 
        pos = ArrayGetIndex(arr, value, compMethod) 
        If Isnull(pos) Then 
                SearchAndDestroy = arr 
                SearchAndDestroy = ArrayRemove(arr, pos) 
        End If 
End Function 

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...