I’m trying to figure out how (if it’s possible) to go to a particular position in a list so that I can get whatever the value is that’s at that position in the list of values.
For example - I have a list of names [let’s say Bill, John, Sue, Dave]…but I don’t know ahead of time what names might be in the list when I access the field. The list is in a multivalue field on a form. What I want to do is say, give me the value of the 1st item in the list, or the 3rd, or whatever.
I’ve been exploring @For, @Member, Arrays, etc but they all seem to indicate that I have to know the value of what I’m trying to find in the list…but I don’t.
Am I missing the forest for the trees? Any help is appreciated.
I prefer to do this in LS but will take any advice available!!
In the event that it helps to know exactly what I’m trying to accomplish: I want to try to assign documents to users in a “round robin” fashion. I want to loop through 1 or more documents and for each document set an “assignee” field equal to a name of an individual. I know I can access the list of individuals based on some rules I have set and I’ve figured out some possible logic to use to loop through the list of individuals and not keep assigning to the same individual over and over again…but I can’t figure out how to loop through the list without knowing what’s in the list. I figured if I set a counter on the document to “remember” which position in the list received the last document I could just say, if the counter < the number of elements in the list then increment the counter and assign to whoever is at that position in the list. If the counter = the elements in the list then set counter = 1 and use first value in the list.
Subject: Going to a particular position in a list…
Unless I am missing something: A multi-value field is accessible as a list in formula language or as an array in LotusScript. So, the shortest notation to e.g. get the third name in field Names would simply be
Names[3]
You can use a numeric variable instead of providing the index number at compile time like
Names[counter]
In LotusScript you would use something like
counter = … your logic to calculate the correct counter …
name = NotesDocument.GetItemValue(“Names”)(counter)
Subject: Going to a particular position in a list…
I think you explained the solution pretty well in your last paragraph…
If you have the values in a field on the document, you can just access them like:
Notesdocument.FieldName(index)
The field is an array, and you just use the value of the index you choose. You don’t have to know what the value of of the field beforehand. Use Ubound to get the upper limit of the array.
If you want to use @Formula, you should take a look at @Subset.
Subject: RE: Going to a particular position in a list…
Ok - Thanks for the responses. I finally got this working…as in most things I knew exactly what I wanted to do just didn’t know the appropriate commands, syntax, etc. Here’s my script…still needs some fine tuning but it works!
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim counter As Variant
Dim size As Variant
Dim index As Integer
Dim view As NotesView
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim assignee As String
Dim adoc As NotesDocument
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set view = db.GetView ("Admin\AssignRulesLookup")
Set doc = dc.GetFirstDocument
index = 0
While Not (doc Is Nothing)
alob = doc.LOB
awa = doc.WAInd
key = alob(0) & awa(0)
Set adoc = view.GetDocumentByKey (key )
If Not (adoc Is Nothing) Then
counter = adoc.GetItemValue("arCounter")
size = adoc.GetItemValue("arGroupSize")
If counter(0) < size(0) Then
index = counter(0)
Else
index = 0
End If
assignee = adoc.GetItemValue("arAssignees")(index)
index = index + 1
adoc.arCounter = index
Call adoc.Save(True,False,False)
Else
assignee = ""
End If
doc.arProcessed = "Yes"
doc.WAAssignee = assignee
Call doc.Save(True,False,False)
Set doc = dc.getnextdocument( doc )
Wend