I am trying to use the "ReplaceItemValue" in lotus script for a multi-value field, with the following code:
(Functionality is when the field 'Region' has the value "SL-BAO" or "SL-S&T" it should replace them with "SL-S&A". Other values should be kept as such)
Sub Initialize
Dim session As New NotesSession
Dim uiws As New NotesUIWorkspace
Dim doc As NotesDocument
Dim doccoll As NotesDocumentCollection
Dim i,j As Integer
Dim itm1,itm2 As NotesItem
Set uiView = uiws.Currentview
Set docColl = uiView.Documents
Set doc = docColl.Getfirstdocument()
Dim tmpval() As String
j=1
While Not doc Is Nothing
For i=0 To UBound(doc.Region)
ReDim Preserve tmpval(i+1)
If (doc.Region(i) ="SL - BAO") Or (doc.Region(i) ="SL - S&T") Then
tmpval(i)="SL - S&A"
Else
tmpval(i)=doc.Region(i)
End If
Next
Call doc.ReplaceItemValue("Region",FullTrim(tmpval))
Call doc.Save(True,False)
Set doc=doccoll.GetNextDocument(doc)
Wend
End Sub
Unfortunately, the code doesn't properly replaces the values. When the field has "SL-S&T" alone, after running the script, it returns with two values.. Similar scenario for all cases.. the code keeps returning garbage values.
Kindly help... Thanks in advance..
tmpval(i)="SL - S&A"
try usingArrayAppend
to add new elements to the end of your array. – Naveen