Update a Value from a Item Collection.

0 pts.
Tags:
Lotus Domino
Dear collegues I have a big problem.: I build one agent to update the current value "nomAntic" (a USERNAME search key) with a new value "nomNou" (A USERNAEM key, both supplied from a INPUTBOX) in all READERS or AUTHORS fields of the document. The agent runs over a document selection. For each document (While), I search into all Items (Forall i in doc.items) and for each Item (IsAuthors or IsReaders), next I search for the occurrence of the suplied USERNAME key into the list values (Forall j in item.Values). I append the new value into the collection -TextList-, But How I delete the current collection's value??It's possible to Replace the values in a TextList? Sub Initialize Dim ses As New NotesSession Dim db As NotesDatabase Dim vw As NotesView Dim ndc As NotesDocumentCollection Dim doc As NotesDocument Dim item As NotesItem Dim itemName As String Dim nomAntic As String Dim nomNou As String Dim ItemValue As String Set db = ses.CurrentDatabase Set ndc = db.UnprocessedDocuments If ndc.Count = 0 Then Messagebox "Agent modifica Uname: No s'ha seleccionat cap document, el programa finalitzara la seva execucio" Exit Sub End If nomAntic = Inputbox$("Quin usuari Notes vols substituir?") nomNou = Inputbox$("Especifica el nou usuari Notes") If nomAntic = "" Then Messagebox "Agent modifica Uname: No s'ha triat un usuari per substtiuir, el programa finalitzara la seva execucio" Exit Sub End If If nomNou = "" Then Messagebox "Agent modifica Uname: No s'ha especiificat cap nou usuari Notes, l'usuari especificat anteriorment sera eliminat" End If 'Messagebox "Agent modifica Uname :Recorrem tots els document seleccionats" Set doc = ndc.GetFirstDocument While Not ( doc Is Nothing) Forall i In doc.Items itemName = i.Name 'Messagebox "Processant els valors del Camp : " & ItemName If (i.IsAuthors Or i.IsReaders) Then Messagebox "Agent modifica Uname: El camp " & itemName & " es un camp tipus AUTHORS o READERS" Set item = doc.GetFirstItem(itemName) Forall v In Item.Values If v = nomAntic Then Messagebox "Agent modifica Uname: El camp " & itemName & " conte una entrada amb el nom especificat " & nomAntic Call item.AppendToTextList( nomNou ) Call Doc.Save(True,True) Messagebox "Agent modifica Uname: El camp " & itemName & " s'ha afegit una entrada amb el nom especificat " & nomNou Else Messagebox "Agent modifica Uname: No s'ha trobat l'usuari especificat en cap camp AUTHORS o READERS del document " Exit Forall End If End Forall End If Call doc.Save( True,True) End Forall Set doc = ndc.getNextDocument(doc) Wend End Sub Sincerely
ASKED: July 7, 2006  9:19 AM
UPDATED: July 10, 2006  10:01 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

onacorpuscle,

You can delete the current item’s value by setting its value to an empty string (item.value = “”). You can manipulate the values array to replace/remove specific values. The Textlist of the NotesItem object is automatically updated to reflect the changes. So, if your NotesItem object item has a TextList of “One;Two;Three;Four” you can change the third value and remove the second value by creating a new array (lArray) with new values (“One;Three (3);four”) and assigning that array to the item.values array (item.values = lArray).

Here is a function that I wrote to create an array from a textlist:
Function getArrayFromTextList(aList As String) As Variant
Dim lArr() As String
Dim lIndex As Integer
Dim lIndex2 As Integer
Dim lItem As String

Redim lArr(0)
lIndex = 1
Do
lIndex2 = Instr(lIndex, aList, “,”)
If lIndex2 > 0 Then
lArr(Ubound(lArr)) = Mid(aList, lIndex, lIndex2 – lIndex)
lIndex = lIndex2 + 1
Redim Preserve lArr(Ubound(lArr) + 1)
Else
lArr(Ubound(lArr)) = Mid(aList, lIndex)
End If
Loop Until lIndex2 = 0

getArrayFromTextList = lArr

End Function

Here is a subroutine for adding unique values to the values array of a NotesItem object:
Sub addToValues(aItem As NotesItem, aValue As Variant)
Dim lIndex As Integer

mValues = aItem.Values

If Isarray(aValue) Then
For lIndex = 0 To Ubound(aValue)
If Instr(Lcase(aItem.Text), Lcase(aValue(lIndex))) = 0 Then
Redim Preserve mValues(Ubound(mValues) + 1)
mValues(Ubound(mValues)) = aValue(lIndex)
End If
Next
Else
If Instr(Lcase(aItem.Text), Lcase(aValue)) = 0 Then
Redim Preserve mValues(Ubound(mValues) + 1)
mValues(Ubound(mValues)) = aValue
End If
End If

aItem.Values = mValues

End Sub

With some modifications, you should be able to use the code above to help accomplish your task.

Charles

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Brooklynegg
    You could also do this with a one-line Evaluate using @replace. This would eliminate one of your loops. Using Evaluate in LotusScript to run @Formula code can be extremely powerful and fast.
    3,845 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following