I’ve written a test project having two databases (field info given below). Basically I’m testing updating a field in Target that uses a lookup( into the Source database. The user will be manually updating the “sourceData” field, and I want the “targetField” field updated using Field Properties>Code.
DB: Source, Fields: id (text), sourceData (integer)
id sourceData
a 4
b 3
c 7
d 8
DB: Target, Fields: id (text), data (integer), targetField (integer)
id data targetField
a 1 2 <code is defined for this field, see below>
b 2 5
c 3 10
d 7 16
Field Properties>Code (field=targetField). I broke down the steps and added a message for debug purposes.
------------ Code -------------
local d
d = lookup("Source", id, id, sourceData)
message "autocode d = " + d
targetField = d + data
The messages in the Update Target procedure (below) are for debugging.
Target:Update Target procedure:
--------------- Update Target ---------------
setactivedatabase "Target"
local numRec, n
n = 1
numRec = info("records")
firstrecord
runfieldcode «targetField»
save
message "new field value: " + targetField
stop
; traverse the records
loopwhile n <= numRec
runfieldcode «targetField»
message "new field value: " + targetField
save
downrecord
n = n+1
endloop
Results.
Before putting runfieldcode, save, message before the loop, the code filled in targetField correctly except for the first record. I put in the code up to stop to test just the first record. Output:
" new field value: 2"
… and that’s it. I did not get message "autocode d = "+d executed.
I expect the new value for targetField to be 5 instead of 2, which was the “old” value.
When running the loop, I did get the autocode messages for all records except for the first one.
Why is the first record’s Code not executing?