sachinbaan
4th February 2015, 08:55
hi,

I am trying to add record through AFS in labor cost, but I am facing strange problem, I don't know whether there is problem in my code or something else,

but when first time I try to insert it gives error "enter value for employee field" even though value is there, now for the first time i inserted a record manually, and then tried with AFS , result is records are getting inserted.


function extern domain tcbool ltmig.commondll.tpppc2531m000.maintain.labor.cost(
domain tcemno i.emno,
domain tccprj i.cprj,
domain tcccp.yrno i.yera,
domain tcccp.peri i.peri,
domain tppdm.cspa i.cspa,
domain tppdm.cact i.cact,
domain tppdm.task i.task,
domain tccpcp i.ccco,
domain tcckow i.cwgt,
domain tppdm.aalc i.amoc,
domain tcdate i.rgdt,
domain tcccp.yrno i.cyea,
domain tcccp.peri i.cper,
domain tcemm.grid i.eunt,
domain tcccur i.ccur,
ref domain tppdm.serd i.serd,
ref string err.msg)
{
string s.sern(3)
stpapi.put.field("tpppc2531m000", "tpppc231.year", str$(i.yera))
stpapi.put.field("tpppc2531m000", "tpppc231.peri", str$(i.peri))
stpapi.put.field("tpppc2531m000", "tpppc231.emno", i.emno)

ret = stpapi.change.view("tpppc2531m000", err.msg)
if isspace(err.msg) then
ret = stpapi.synchronize.dialog("tpppc2531m000", "ADD", err.msg)
if ret = 1 then
stpapi.put.field("tpppc2131s000", "tpppc231.year", str$(i.yera))
stpapi.put.field("tpppc2131s000", "tpppc231.peri", str$(i.peri))
stpapi.put.field("tpppc2131s000", "tpppc231.emno", i.emno)
stpapi.put.field("tpppc2131s000", "tpppc231.cprj", i.cprj)
stpapi.put.field("tpppc2131s000", "tpppc231.cspa", i.cspa)
stpapi.put.field("tpppc2131s000", "tpppc231.cact", i.cact)
stpapi.put.field("tpppc2131s000", "tpppc231.task", i.task)
stpapi.put.field("tpppc2131s000", "tpppc231.ccco", i.ccco)
stpapi.put.field("tpppc2131s000", "tpppc231.curc", i.ccur)
stpapi.put.field("tpppc2131s000", "tpppc231.cwgt", i.cwgt)
stpapi.put.field("tpppc2131s000", "tpppc231.amoc", str$(i.amoc))
stpapi.put.field("tpppc2131s000", "tpppc231.entu", i.eunt)

ret = stpapi.insert("tpppc2131s000", true, err.msg)
if ret = 1 then
stpapi.get.field("tpppc2131s000", "tpppc231.sern", s.sern)
i.serd = lval(s.sern)
stpapi.end.session("tpppc2131s000")
stpapi.end.session("tpppc2531m000")
return(true)
endif
endif
endif
stpapi.end.session("tpppc2531m000")
return(false)
}

bhushanchanda
4th February 2015, 12:07
Hi,

The message may be misleading, I see you are not updating the serial number i.e. sern. Just try to assign it some value.

Also, there are a few other fields which are defaulted like

Posting type - tpppc231.tetc = tpppc.tetc.manu
Settlement Origin - tpppc231.sttl = tppdm.yeno.no
HRA - tpppc231.serc = 0
tpppc231.sern = 9999
Cost Period Code - tpppc231.cpth (Which comes from parameters tpppc000.cpth)

As, for the first record, there was no reference to all these values the program was giving error through AFS, for the second time, the first record became the reference.

This happens in a lot of the session due to badly written code for the session. Generally, the reason for this is, the field initialization may be done in the before.display.object: section instead of DAL(I guess this table doesn't have a DAL) in the script which will never get triggered by AFS.

So, not your code problem, but problem with the standard script.

So, to avoid issues. Use DAL instead to avoid the dependence on the standard and it will work. :) or if you want to stick to AFS, you need to figure out which fields are defaulted and with what values, and accordingly perform AFS.

mark_h
4th February 2015, 17:12
So, to avoid issues. Use DAL instead to avoid the dependence on the standard and it will work. :) or if you want to stick to AFS, you need to figure out which fields are defaulted and with what values, and accordingly perform AFS.

Or play it safe and put all the fields. I have had to do that on a couple of sessions. Mainly because users will "save defaults" then when they run the AFS code and it opens the session - it will open with the users defaults. If you do not put all the fields it might use something from their session defaults.

bhushanchanda
4th February 2015, 17:15
Or play it safe and put all the fields. I have had to do that on a couple of sessions. Mainly because users will "save defaults" then when they run the AFS code and it opens the session - it will open with the users defaults. If you do not put all the fields it might use something from their session defaults.

A better advice!

sachinbaan
5th February 2015, 05:08
ok, let me try with all fields...

mark_h
5th February 2015, 20:51
Is employee id a character field on your system? It is long on my system.

Another thing to try if that does not work is to put the record twice. Seems like I had to do that one before.