rduncan10
15th January 2008, 21:20
Hi,

I'm trying to write some AFS code to load financial budgets in the session tffbs1101m000, in Baan 4 c4.

The code here runs without any errors, but when it gets to the end, there is no record inserted. Any idea why?

stpapi.put.field("tffbs1101m000", "tffbs101.year", str$(year.i))
stpapi.put.field("tffbs1101m000", "tffbs101.budg", str$(budg.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim1", str$(dim1.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim2", str$(dim2.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim3", str$(dim3.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dbcr", str$(dbcr.i))
stpapi.put.field("tffbs1101m000", "tffbs101.disb", "")
stpapi.put.field("tffbs1101m000", "year.amnt", str$(0))
ret = stpapi.change.view("tffbs1101m000", err)
for x = 1 to 12
| Amounts stored in an array.
stpapi.put.field("tffbs1101m000", "tffbs101.prod", str$(x))
stpapi.put.field("tffbs1101m000", "tffbs101.amnt", str$(per.amnt(x)))
ret = stpapi.update("tffbs1101m000", 1, err)
if ret = 0 then
stpapi.recover("tffbs1101m000", err)
else
| I've tried it with and without this line below.
ret = stpapi.save("tffbs1101m000", err)
endif
endfor
stpapi.end.session("tffbs1101m000")

Thanks,
Rob

mark_h
16th January 2008, 14:34
Have you tried stpapi.insert versus stpapi.update?

rduncan10
16th January 2008, 15:21
I did that first, but it does not work. When you manually key data into the session and move from the header to the detail, Baan automatically creates the twelve period records, with zero amounts.

So when I used stpapi.insert, I got the error "Record already exists".

mark_h
16th January 2008, 18:12
See this:

stpapi.put.field("tffbs1101m000", "tffbs101.year", str$(year.i))
stpapi.put.field("tffbs1101m000", "tffbs101.budg", str$(budg.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim1", str$(dim1.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim2", str$(dim2.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim3", str$(dim3.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dbcr", str$(dbcr.i))
stpapi.put.field("tffbs1101m000", "tffbs101.disb", "")
stpapi.put.field("tffbs1101m000", "year.amnt", str$(0))
ret = stpapi.change.view("tffbs1101m000", err)
| Assuming that the change view created the 12 periods.
for x = 1 to 12
stpapi.put.field("tffbs1101m000", "tffbs101.year", str$(year.i))
stpapi.put.field("tffbs1101m000", "tffbs101.budg", str$(budg.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim1", str$(dim1.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim2", str$(dim2.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dim3", str$(dim3.i))
stpapi.put.field("tffbs1101m000", "tffbs101.dbcr", str$(dbcr.i))
stpapi.put.field("tffbs1101m000", "tffbs101.disb", "")
stpapi.put.field("tffbs1101m000", "year.amnt", str$(0))
stpapi.put.field("tffbs1101m000", "tffbs101.prod", str$(x))
ret = stpapi.find("tffbs1101m000", err)
| Amounts stored in an array.
stpapi.put.field("tffbs1101m000", "tffbs101.amnt", str$(per.amnt(x)))
ret = stpapi.update("tffbs1101m000", 1, err)
if ret = 0 then
stpapi.recover("tffbs1101m000", err)
else
| I've tried it with and without this line below.
ret = stpapi.save("tffbs1101m000", err)
endif
endfor
stpapi.end.session("tffbs1101m000")


Please note that this code assumes the change view creates the 12 periods. I do not see why you put the period a second time. I think the first goal should be to make sure the 12 periods are created. Then the find will locate the record and you can update the amount.