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
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
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
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
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("Dwe llingNumbe r")(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(Fiel d1)
tempList(position) = RateForm.GetItemValue(Fiel d2)(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.
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("Dwe
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(Fiel
tempList(position) = RateForm.GetItemValue(Fiel
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
change this :
Field2 = "RateForm." & Field1
' RateForm.mF1_Desc1 = tempList
Field2 = tempList
to this :
call rateform.ReplaceItemValue(
cheers,
Tom
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
But, it is not possible to generate dynamic fields on fly.