tomzak
14th December 2009, 12:40
Hallo @all

i'm writing a function to insert data via AFS into a table. This table is created by us. It has a dynamic session with the session type "display" and the window type "modal window with menu" as main. Then there is a secend session with session type "maintain" and window type "list window". My code to insert data is the following:


retVal = stpapi.browse.set("lhpai0154m000","last.set",w.err.msg)
retVal = stpapi.mark("lhpai0154m000",w.err.msg)

retVal = stpapi.synchronize.dialog("lhpai0154m000", "add", error.msg)
| retVal = stpapi.synchronize.dialog("lhpai0154m000", "modify", error.msg)
if (retVal = 0) then
return (retVal)
endif

stpapi.put.field("lhpai0154s000", "lhpai054.year", str$(p.year))
stpapi.put.field("lhpai0154s000", "lhpai054.prod", str$(p.prod))
stpapi.put.field("lhpai0154s000", "lhpai054.sern", str$(CheckSern(p.year, p.prod)))
stpapi.put.field("lhpai0154s000", "lhpai054.emnp", str$(p.emnp))
stpapi.put.field("lhpai0154s000", "lhpai054.pdno", str$(p.pdno))
stpapi.put.field("lhpai0154s000", "lhpai054.opno", str$(p.opno))
stpapi.put.field("lhpai0154s000", "lhpai054.cprj", str$(p.cprj))
stpapi.put.field("lhpai0154s000", "lhpai054.cwoc", str$(p.cwoc))
stpapi.put.field("lhpai0154s000", "lhpai054.ccos", str$(p.ccos))
stpapi.put.field("lhpai0154s000", "lhpai054.gmka", str$(p.gmka))
stpapi.put.field("lhpai0154s000", "lhpai054.izst", str$(p.izst))
stpapi.put.field("lhpai0154s000", "lhpai054.ddtp", str$(p.ddtp))
retVal = stpapi.insert("lhpai0154s000", 1, error.msg)
| retVal = stpapi.update("lhpai0154s000", 1, error.msg)
if (retVal = 0) then
rc = stpapi.recover("lhpai0154s000", w.err.msg)
endif


When i execute the code then I get an errormessage "Command disabled" at the stpapi.insert. When I change the "add" and "insert" to "modify" and "update" then the record is updated correctly. Has anyone an idea what's wrong in my code

thank's
Thomas

Gomesh.m
14th December 2009, 12:56
Hi,

I think the problem is, when u used stpapi.mark function, it will select a record, and the selected record will open it in modify mode.

If u comment the stpapi.mark function and check how it 's work.

Best Regards,
Gom

tomzak
14th December 2009, 13:38
Hi gom

the mark is only for the update, i forgott it to comment out. This isn't the problem, sorry

Thomas

mark_h
14th December 2009, 16:02
Is this baan 4 or baan 5? Anyway - shouldn't the insert be on the main session? From the example in the documentation.


ret = stpapi.synchronize.dialog("dtfsa1501m000", "add", error.msg)
if ret then
stpapi.put.field("dtfsa1101s000", "dtfsa101.seno", str$(new.seno)
stpapi.put.field("dtfsa1101s000", "dtfsa101.name", new.name)
ret = stpapi.insert("dtfsa1501m000", true, error.msg)
if not ret then
ret = stpapi.recover("dtfsa1101s000", error.msg)
endif
endif
stpapi.end.session("dtfsa1501m000", error.msg)

tomzak
14th December 2009, 19:03
Hi mark_h

1.) It's Baan 5
2.) You are right, but it didn't change anything

Thomas

mark_h
15th December 2009, 15:36
Is the insert command turned on for adding records to the session?