Virender
19th September 2011, 14:48
Hi

I am writing an AFS to create a new asset, the first part to add a new assets using session tffam1500m000 Assets is fine and a new asset is created.

Further I am closing the session and reopening it with the added asset.
Then calling form, specific, Assets book session.
Selecting 'Fin' asset book and modifying.
And updating assets las date of dep, ytd depreciation etc.

The problem is session is giving error while updating the record, the message is last depreciation date can not be before service date.

I checked using stpapi.get.field statment, the m.anbr1 is empty which means the session is not opened correctly.

Please suggest if the steps are correct in the script.
-------------------
stpapi.synchronize.dialog("tffam1500m000","Add",msg)

stpapi.put.field("tffam1100s000","tffam100.anbr",m.anbr)
stpapi.put.field("tffam1100s000","tffam100.aext",m.aext)
stpapi.put.field("tffam1100s000","tffam100.desc",m.desc)
stpapi.put.field("tffam1100s000","tffam100.cost",str$(m.cost))
stpapi.put.field("tffam1100s000","tffam100.ctgy",m.ctgy)
stpapi.put.field("tffam1100s000","tffam100.sctg",m.sctg)
stpapi.put.field("tffam1100s000","tffam100.agrp",m.agrp)
stpapi.put.field("tffam1100s000","tffam100.srvc",str$(m.srvc))
stpapi.put.field("tffam1100s000","tffam100.pudt",str$(m.pudt))
stpapi.put.field("tffam1100s000","tffam100.tqty",str$(m.tqty))
stpapi.put.field("tffam1100s000","tffam100.ownc",str$(tffam.ownc.owne))

stpapi.insert("tffam1500m000", 0, msg)
stpapi.save("tffam1500m000", msg)
if msg <> "" then
message(msg)
stpapi.recover("tffam1100s000", msg)
endif

stpapi.end.session("tffam1500m000")
| ---- ok till here

stpapi.put.field("tffam1500m000","tffam100.anbr",m.anbr)
retval1 = stpapi.find("tffam1500m000",msg)
stpapi.get.field("tffam1500m000","tffam100.anbr",m.anbr1)

stpapi.form.command("tffam1500m000", 2, "tffam1510m000",msg)
stpapi.put.field("tffam1510m000","tffam110.book",m.book)
retval1 = stpapi.find("tffam1510m000",msg)
stpapi.synchronize.dialog("tffam1510m000","Modify",msg)
stpapi.get.field("tffam1110s000","tffam110.cost",m.cost1)

stpapi.put.field("tffam1110s000","tffam110.last",str$(m.last))
stpapi.get.field("tffam1110s000","tffam110.last",m.last1)
retval1 = stpapi.update("tffam1510m000", 0, msg)

stpapi.put.field("tffam1110s000","tffam110.ltdd",str$(m.ltdd), 1)
stpapi.get.field("tffam1110s000","tffam110.ltdd",m.ltdd1, 1)
stpapi.put.field("tffam1110s000","tffam110.ytdd",str$(m.ytdd), 1)
stpapi.get.field("tffam1110s000","tffam110.ytdd",m.ytdd1, 1)
stpapi.put.field("tffam1110s000","tffam110.depr",str$(m.depr), 1)

retval1 = stpapi.update("tffam1510m000", 0, msg)
stpapi.end.session("tffam1500m000")

|stpapi.put.field("tffam1110s000","form.liyr",str$(m.liyr))

retval1 = stpapi.update("tffam1510m000", 0, msg)
stpapi.end.session("tffam1500m000")
------------

Thanks
Virendra

mark_h
20th September 2011, 15:35
Your profile says Baan IV, but this looks like 5 or LN code. I won't be much help since we do not have these sessions and I do not use LN. So here are my questions on this piece of code to start with:

stpapi.put.field("tffam1500m000","tffam100.anbr",m.anbr)
retval1 = stpapi.find("tffam1500m000",msg)
stpapi.get.field("tffam1500m000","tffam100.anbr",m.anbr1)


You open tffam1500m000 sync it up and then insert okay. Now you close it - you reopen with a put field tffam1500m000. At that point would you need to sync it again - maybe using display mode? Wouldn't the get field be on the tffam1100s000 sub-session? I am wondering if the find is actually working - does it return 1?

Plus I wonder if you need this stpapi.synchronize.dialog("tffam1500m000","Modify",msg)
before starting on the tffam1510 process. Just guessing since we do not have this session at all.

patriciosoria
15th October 2011, 01:58
Hi,

I have a same problem, i solved with the next script

field.proc = 0
| stpapi.synchronize.dialog("tffam1500m000","Modify", error.msg) | not necesary
stpapi.put.field("tffam1500m000", "tffam100.anbr", m.anbr)
stpapi.put.field("tffam1500m000", "tffam100.aext", m.aext)
ret = stpapi.find("tffam1500m000", error.msg)
if ret = 1 then
field.proc = 1
else
stpapi.put.field("tffam1500m000", "tffam100.anbr", m.anbr)
stpapi.put.field("tffam1500m000", "tffam100.aext", m.aext)
ret = stpapi.find("tffam1500m000", error.msg)
if ret = 1 then
field.proc = 1
endif
endif

if field.proc = 1 then
stpapi.mark("tffam1500m000", error.msg)
| only verify
stpapi.get.field("tffam1500m000", "tffam100.anbr", m.var) |
stpapi.get.field("tffam1500m000", "tffam100.aext", m.var)
stpapi.get.field("tffam1500m000", "tffam100.stat", m.var) |
if m.var = "2" then
stpapi.handle.subproc("tffam1500m000", "tffam1204m000", "add")
stpapi.form.command("tffam1500m000", 2,"tffam1204m000",error.msg) |Proccess
fech.stri = str$(date.d)
stpapi.get.field("tffam1204m000", "tffam100.anbr", m.var) | Only verify
stpapi.get.field("tffam1204m000", "tffam100.aext", m.var)
stpapi.put.field("tffam1204m000", "form.date", m.date.string)
stpapi.put.field("tffam1204m000", "form.reas", m.reas)
stpapi.put.field("tffam1204m000", "print.report", "2") || don“t print
stpapi.enum.answer("tffam1204m000", "tffams0027", tcyesno.yes)
stpapi.form.command("tffam1204m000", 5,"dispose.asset.book", error.msg)
endif
endif

stpapi.end.session("tffam1204m000", error.msg)
stpapi.end.session("tffam1500m000", error.msg)