Link to home
Start Free TrialLog in
Avatar of GaryZ
GaryZ

asked on

Updating a field on a form using LotusScript

I am creating a loop that reads an array and dynamically builds field names from the form. Once I have the value in the field I need to update another field with the same information, this field name is generated dynamically. What command do I use to do this?

This works fine:

doc.mF1_Desc1 = tempList

However is I build the field name in a String it, this doesn't work, which I assume is because Field2 is not on the database  Field2 = doc.mF1_Desc1

Field2 = tempList  
Avatar of madheeswar
madheeswar
Flag of Singapore image

u should use doc.field2=templist

But, it is not possible to generate dynamic fields on fly.
What u want to do exactly?
No,

doc.mF1_Desc1

returns a variant.  So if Field2 is a String, you get a type mismatch.  Try this :

dim result as variant

result = doc.mF1_Desc1

forall values in result
'now the individual values are accessible
print " result : " & values
end forall

Another way of writing this, that may be clearer, is to use the getitemvalue method in notesdocument, which returns a variant.  It's actually the same as using the short syntax.

result = doc.getitemvalue( "mF1_Desc1" )

If you want it to return a string, use
dim resultString as string
resultString = doc.getfirstitem( "mF1_Desc1" ).text

note that this will give an error, if the item does not exist on the document.

cheers,

Tom
Avatar of GaryZ
GaryZ

ASKER

OK. Let's try this again.

Here is the complete code:

      Dim session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CurrentDatabase
      Dim RateForm As NotesDocument
      Set RateForm = session.DocumentContext
      
      Dim tempList As Variant
      Dim position As Variant
      Dim temp As Variant
      
      
      Dim FieldList As Variant
      FieldList = RateForm.FieldNames
      Dim FieldName() As String
      Dim FieldSize() As String      
      Dim FieldType() As String      
      Dim FieldValue As Variant
      Dim Field1 As String
      Dim Field2 As String
      
      position = RateForm.GetItemValue("DwellingNumber")(0)-1
      
      For cntr = Lbound(FieldList) To Ubound(FieldList)
            
            Redim Preserve FieldName(cntr)                  
            FieldName(cntr) = FieldList(cntr)
            Mid(FieldName(cntr),6) = ReplaceChar                  
            FieldName(cntr) = Mid$(Fieldname(cntr),6)                  
            Field1 = "m" + FieldName(cntr)
            Field2 = FieldName(cntr)
            tempList =  RateForm.GetItemValue(Field1)
            tempList(position) = RateForm.GetItemValue(Field2)(0)
            Field2 = "RateForm." & Field1
            
'            RateForm.mF1_Desc1 = tempList
            Field2 = tempList
            
      Next cntr
      
The problem I am having is geting the value back to a list field on the form.




So you want the varialbe 'templist' in a field 'Field2' on your document ?

change this :

          Field2 = "RateForm." & Field1
'          RateForm.mF1_Desc1 = tempList
          Field2 = tempList

to this :

call rateform.ReplaceItemValue( "RateForm." & Field1 , tempList )

cheers,

Tom
ASKER CERTIFIED SOLUTION
Avatar of Bozzie4
Bozzie4
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial