Hello,I have a problem with a LS agent.
The agent needs to go through all of the documents in a view.
In each document it needs to swap the value in a field (Level1) if the field contains a given value. – so the field Level1 in a document contains aaa,bbb,ccc,ddd I want to swap out ccc with zzz.
I can find the location of the value i.e. it is at Level1(2).
But when I try and swap it: doc.level1(i) = “zzz” I only get an error – (here i = 2, it’s in a loop.)
Using ReplaceItemValue doesn’t work either as I cant specify which element to replace:
doc.ReplaceItemValue “Level(“ & i & “)”, “zzz”
Has anyone got any ideas? Thanks loads!
Jimmy
Subject: Replace Item Value - error
Is your field Level1 multivalue? In other words are we dealing with:
“aaa,bbb,ccc,ddd” , in which case you need to parse the string
or
“aaa”
“bbb”
“ccc”
“ddd”
in which case you need to loop through the values array of the notes item and test each element.
Your replaceitemvalue example (if accurate) is incorrect (but you wouldn’t use it that way anyway…)
Call doc.replaceItemValue(“Level” & cstr(i),“zzz”)
would work, but would set the whole field to be “zzz”.
Do this:
Dim varLevel1 as Variant
varLevel1=doc.level1
Forall x in varLevel1
if x=“ccc” then
x=“zzz”
End if
End forall
Call doc.replaceItemValue(“Level1”,varLevel1)
Subject: RE: Replace Item Value - error
Dim List1 As VariantDim List2 As Variant
List1 = doc.Level1
List2 = Fulltrim(Arrayreplace( List1, “ccc”, “zzz” ))
doc.Level = List2
Call doc.Save(True, True)