For loop in Lotus Script

Hi , Need some help on a 'for loop' in LotusScript.
I'm reading values from one form and updating them into another form.

The first form has a text field named TotalMANs. The value in this field can be between 1 to 175.

Also there are 175 other fields in the form which are called as MAN1 , MAN2 , MAN3, MAN4, MAN5, MAN6, UNTIL........ MAN175

Lets say I'm referring these fields in my agent as doc.TotalMANs,  doc.MAN1, doc.MAN2, doc.MAN3, doc.MAN4, UNTIL..............doc.MAN175

This is what I want to do now:
If the doc.TotalMANs value is 5 Then
 I want to read values from doc.MAN1, MAN2,MAN3,MAN4,MAN5 and append it in another field from a different form (doc2.MAN which is a multi-value field).

Similarly If the doc.TotalMans value is 100 Then
 I want to read values from doc.MAN1, MAN2.. until doc.MAN100 and append all these values to doc2.MAN.

So the loop should run based on the doc.TotalMans value.

I know I've to write a for loop for this.
Please advise
thanks
Kalios
LVL 2
kaliosAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
HemanthaKumarConnect With a Mentor Commented:
The loop should look like this

dim ws as new notesuiworkspace
dim note as NotesDocument
dim item as NotesItem
set note = ws.CurrentDocument.Document
For i = 1 to note.TotalMans(0)
 Set item = note.GetFirstItem( "Man" & cstr(i) )
 v = item.Values(0)
Next i

~Hemanth
0
 
madheeswarCommented:
the below code should work. And I assume,you have some key to fetch another field from a different form.

Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim curdoc As notesdocument
      Dim uidoc As notesuidocument
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      Dim arr() As String
      
      Set uidoc=ws.currentdocument
      Set curdoc=uidoc.document
      Set db=ss.currentdatabase
      Set view=db.getview("urViewName")
      
      Dim item As notesitem
      
      Dim x As Integer
      Dim k As Integer
      k=0
      For x=1 To curdoc.totalMans(0)
            k=k+1
            tmpfld="Man"+Cstr(x)
            Set item=curdoc.getfirstitem(tmpfld)
            Redim Preserve arr(k)
            arr(k)=item.values(0) 'I assume Man1,Man2,....are not multivalue fields. If they are multivalue, then need to use loop here.
      Next
      tmpkey=curdoc.YourkeyField(0)
      Set dc=view.getalldocumentsbykey(tmpkey)
      Set doc=dc.getfirstdocument
      While Not doc Is Nothing
      'Your another field.
            doc.Man=arr
            Call doc.save(True,True)
            Set doc=dc.getnextdocument(doc)
      Wend
      
End Sub
0
 
madheeswarConnect With a Mentor Commented:
try this:
Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim curdoc As notesdocument
      Dim uidoc As notesuidocument
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      Dim arr() As String
      
      Set uidoc=ws.currentdocument
      Set curdoc=uidoc.document
      Set db=ss.currentdatabase
      Set view=db.getview("urViewName")
      
      Dim item As notesitem
      
      Dim x As Integer
      Dim k As Integer
      k=0
      For x=1 To curdoc.totalMans(0)
            
            tmpfld="a"+Cstr(x)
            Set item=curdoc.getfirstitem(tmpfld)
            Redim Preserve arr(k)
            arr(k)=item.values(0) 'I assume Man1,Man2,....are not multivalue fields. If they are multivalue, then need to use loop here.
            k=k+1
      Next
      
      tmpkey=curdoc.YourkeyField(0)
      'if the another documents are more than one, then use the below code.
      Set dc=view.getalldocumentsbykey(tmpkey,True)
      Set doc=dc.getfirstdocument
      While Not doc Is Nothing
      'Your another field.
            doc.Man=Fulltrim(arr)
            Call doc.save(True,True)
            Set doc=dc.getnextdocument(doc)
      Wend
      'else if it is ONE document, then use below code:
      Set doc=view.getdocumentbykey(tmpkey)
            'Your another field.
      doc.Man=Fulltrim(arr)
      Call doc.save(True,True)
      
End Sub
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
kaliosAuthor Commented:
Hi Hemanth,

This is what I've so far

Dim k As Integer
Dim MTNItem As NotesItem
Set MTNItem = NCdoc.GetFirstItem("MTN")
      
For k = 1 To doc.TotalMans(0)
      Call MTNItem.AppendToTextList("doc.MAN"+Cstr(k)+ Cstr((0)))            
Next

but i get a error at Call MTNItem.AppendToTextList("doc.MAN"+Cstr(k)+ Cstr((0)))            
object variable not set.

0
 
HemanthaKumarCommented:
hold on.. what you are doing is not right.

First you have to prepare the item name and then get item handle and then get the value

I will try to rewrite your code and see if it works

Dim k As Integer
Dim MTNItem As NotesItem
Set MTNItem = NCdoc.GetFirstItem("MTN")
     
For k = 1 To doc.TotalMans(0)
      Call MTNItem.AppendToTextList(NCdoc.GetItemValue("Man" & cstr(k))(0))
Next
0
 
kaliosAuthor Commented:
Hemanth it does not work with above code: It says object variable not set.

Ok Here is what I've as per your first suggestion. This works . However it is

Dim k As Integer
Dim MTNItem As NotesItem
For k = 1 To doc.Totmans(0)
    Set MTNItem = doc.GetFirstItem( "Man" & Cstr(k) )
    NCdoc.MTN = MTNItem.Values(0)                        
Next

The above works fine. However, each time it is replacing Ncdoc.MTN value. I want to append to NCdoc.MTN.
NCdoc.MTN = MTNItem.Values(0)  should be changed here.

please advise
thanks
Kalios
0
 
kaliosAuthor Commented:
OK got it....here it is

                                                Dim k As Integer
                  Dim MTNItem As NotesItem
                  Dim MANItem As NotesItem
                  Dim NMAN As String
                  
                  For k = 1 To doc.Totmans(0)
                        Set MTNItem = doc.GetFirstItem( "MAN" & Cstr(k) )
                        Let NMAN$ = MTNItem.Values(0)                        
                        Set MANItem = NCdoc.GetFirstItem("MTN")
                        Call MANItem.AppendToTextList(NMAN$)
                  Next

0
 
madheeswarCommented:
Kalios,
What is the difference between my code and the code which u used?

Do u think my code is not performing well?

-Thanks
0
All Courses

From novice to tech pro — start learning today.