Copy value to field

I’m trying to get this formula to read a computed or editable field and then copy the value to another field so I can run a math formula with the field2 value.

I’ve put this formula in a button.

If field = 12 Then field2 = 30

Elseif field = 26 Then field2 = 14

Elseif field = 52 Then field2 = 7

Else NbPaiement2 = 1

End If

I tried putting the @if in the field2 formula but still no go

What would be the problem in the formula ?

Thanks

Subject: copy value to field

What programming language is this?

Subject: RE: copy value to field

Silly fella – it’s LotusScript, but it’s using a whole bunch of undeclared Variant variables instead of addressing the Items of the Document or the Fields of the UIDocument. It likely runs perfectly, but since it’s a no-op, nothing appears to happen unless the debugger’s open.

To the OP:

In Formula Language, one simply uses the name of the field. Not so in LotusScript. LS accesses the elements of a Notes database through a hierarchy of objects. When you create an action, for instance, it starts out like this:

Sub Click(Source As Button)

End Sub

Those lines are important, since they tell Notes where the code is attached and how it is to be called. In this case, it is code called when the associated button is clicked.

Now you need to get and set the field values. You cannot get to the fields directly – you need to go through the container (the document), and you need to make your way TO the document before you can start looking for fields. There are two “free” objects that you can always access in the Notes client – the NotesSession and the NotesUIWorkspace. From them, you can get anywhere else you need to go. In this case, you need to get to the currently-opened document:

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document

End Sub

You can access values directly from the uidocument, but they will always be a single text string. Using the document rather than the uidocument means that multiple values will be separated out, and that the values will (usually) be of the correct data type.

You can access the fields in several ways. From the document, you can use the GetItemValue method, or you can use the “extended class syntax” which allows you to treat the fields as if they were properties of the document object. I prefer the former syntax for a number of reasons:

value = doc.GetItemValue(“FieldName”)

but others are more at home with the extended class syntax:

value = doc.FieldName

BIG NOTE: The values in a NotesItem (the back-end object that represents a field on a form) is ALWAYS an array, even if it only contains one value. You need to keep that in mind when reading a field. So, in order to examine a single value in a field, you need to read a single member of the array:

value = doc.GetItemValue(“FieldName”)(0)

To put a value into a field:

Call doc.ReplaceItemValue(“FieldName”, value)

or

doc.FieldName = value

No matter which syntax you use, you can only assign the ENTIRE value of a field all at once – you can’t simply change one value in a multi-value field.

Subject: RE: copy value to field

Seer!

But while we’re at it: When storing number variable instead of just retrieving them for direct comparison, make sure to choose and appropriate data type. Unlike in @Formulas, there’s no one-fits-it-all number data type, but quite a bunch of them:

Integer

Long

Single Double

Currency

Byte

Be especially warned of the Byte data type. Due to its (intentionally) limited range, it’s rarely used for storing field values anyway, but be warned that writing a Byte value back into a number field does not work.