mig28mx
9th October 2013, 05:02
Hi all,
I´m writting a function using API functions to fill a customized table.
My code looks like:

function crea.linea()
{
stpapi.put.field("tfcmg9167m000", "tfcmg967.info", info.nuevo)
ret1 = stpapi.find("tfcmg9167m000", mensaje)
stpapi.handle.subproc("tfcmg9167m000", "tfcmg9168s001", "add")
stpapi.continue.process("tfcmg9167m000", mensaje)
stpapi.put.field("tfcmg9168s001", "tfcmg968.rfcf", rfcf)
stpapi.put.field("tfcmg9168s001", "tfcmg968.date", str$(date.num()))
stpapi.put.field("tfcmg9168s001", "tfcmg968.ccur", ccur)
stpapi.put.field("tfcmg9168s001", "tfcmg968.tick", str$(tcyesno.yes))
stpapi.put.field("tfcmg9168s001", "tfcmg968.ctra", ctra)
stpapi.put.field("tfcmg9168s001", "tfcmg968.dedu", str$(tcyesno.yes))
stpapi.put.field("tfcmg9168s001", "tfcmg968.tpay", tpay)
stpapi.put.field("tfcmg9168s001", "tfcmg968.tesp", str$(tesp))
stpapi.put.field("tfcmg9168s001", "tfcmg968.retn", str$(tcyesno.no))
stpapi.put.field("tfcmg9168s001", "tfcmg968.isup", str$(isup))
stpapi.put.field("tfcmg9168s001", "tfcmg968.dscr", desc)
stpapi.put.field("tfcmg9168s001", "tfcmg968.leac", leac)
stpapi.put.field("tfcmg9168s001", "tfcmg968.amnt", str$(amnl))
stpapi.put.field("tfcmg9168s001", "tfcmg968.tvat", str$(tcyesno.yes))
stpapi.put.field("tfcmg9168s001", "tfcmg968.ccty", ccty)
stpapi.put.field("tfcmg9168s001", "tfcmg968.cvat", cvat)
stpapi.put.field("tfcmg9168s001", "tfcmg968.vyer", str$(year))
stpapi.put.field("tfcmg9168s001", "tfcmg968.vprd", str$(fprd))
stpapi.put.field("tfcmg9168s001", "tfcmg968.leat", leat)
stpapi.put.field("tfcmg9168s001", "tfcmg968.vamt", str$(vamt))
stpapi.put.field("tfcmg9168s001", "tfcmg968.amth", str$(amnl))
stpapi.put.field("tfcmg9168s001", "tfcmg968.vamh", str$(vamt))

ret = stpapi.insert("tfcmg9168s001", true, mensaje)
if ret = 1 then
stpapi.get.field("tfcmg9168s001", "tfcmg968.lino", pono)
mensaje = sprintf$("Se creó Linea %s para el informe de gastos %s", pono, info.nuevo)
rprt_send()
num.linea = lval(pono)
tipo = 1
proce = 3
stpapi.end.session("tfcmg9168s001")
stpapi.end.session("tfcmg9167m000")
mensaje = ""
else
tipo = 2
proce = 3
mensaje = "Informe "&strip$(info.nuevo)&" "&mensaje
ret = stpapi.recover("tfcmg9168s001", mensaje)
stpapi.end.session("tfcmg9168s001")
stpapi.end.session("tfcmg9167m000")
reg.erroneos = reg.erroneos + 1
error = true
endif
}


and I allways got a message "Currency not defined".

I checked the code where that fills that code and I found the following:

field.tfcmg968.ccur:
before.input:
tfcmg968.ccur = main.ccur
attr.input = false
before.zoom:
tcmcs002.ccur = tfcmg968.ccur
check.input:
select tcmcs002.ccur
from tcmcs002
where tcmcs002._index1 = {:tfcmg968.ccur}
selectdo
selectempty
mensaje("Divisa no definida")
set.input.error("")
endselect


I believe this is why the AFS function is not working.

I tried to define main.curr variable on the program but I have the same result.

Any ideas?
Thank you in advance.

bhushanchanda
9th October 2013, 07:12
Hi,

Does main.ccur has any value? Does tfcmg968.ccur has correct domain?
When your check.input is called, does the field tfcmg968.ccur has any value?

If yes, just give this a try

field.tfcmg968.ccur:
before.input:
tfcmg968.ccur = main.ccur
attr.input = false
before.zoom:
tcmcs002.ccur = tfcmg968.ccur
check.input:
db.set.to.default(ttcmcs002) | clear the table before doing a select
select tcmcs002.ccur
from tcmcs002
where tcmcs002._index1 = {:tfcmg968.ccur}
selectdo
selectempty
mensaje("Divisa no definida")
set.input.error("")
endselect

mark_h
9th October 2013, 15:31
Well that before input kind of precludes tfcmg968 being an input field. Actually what I would do is:


field.tfcmg968.ccur:
before.input:
if not api.mode then
tfcmg968.ccur = main.ccur
attr.input = false
endif
before.zoom:
tcmcs002.ccur = tfcmg968.ccur
check.input:
select tcmcs002.ccur
from tcmcs002
where tcmcs002._index1 = {:tfcmg968.ccur}
selectdo
selectempty
mensaje("Divisa no definida")
set.input.error("")
endselect

This should allow you to input the tfcmg968.ccur when using a function server only. Not really sure where that main.ccur gets set, but putting the custom session in debug mode and running through the afs code should show you want happens.

mig28mx
9th October 2013, 18:52
Hi bhushanchanda and Mark,
Thank you for your answers!

It is seem to me that the only way to correct this error involves to modify the code where the table gets the value of ccur.

I don´t want to change the original code because it not belong to us.
I can make changes just only on the afs sesion.

Another idea?

bhushanchanda
9th October 2013, 20:03
Hi,

As Mark rightly said, you should put your code under debugger to check what does the variable main.ccur have. If you are not looking to change the other code, try these things :-

stpapi.put.field("tfcmg9168s001", "tfcmg968.ccur", trim$(ccur))

Try replacing
stpapi.handle.subproc("tfcmg9167m000", "tfcmg9168s001", "add")

with
ret = stpapi.synchronize.dialog("tfcmg9167m000", "add", error)
|OR
ret = stpapi.synchronize.dialog("tfcmg9167m000", "Add", error)
|OR
ret = stpapi.synchronize.dialog("tfcmg9167m000", "Modify", error)



This will hardly make any difference, as the other part is causing the issues. Check with the developer about that part of code. It might not be supporting AFS. Also, I am seeing a sub section of before.zoom: for that field. What is it for? Is stpapi.zoom.option() missing?

How does it handles the session without AFS? Have you tried it without AFS under debugger?

mark_h
9th October 2013, 22:08
There are a lot of things you can try - I can't really say what might work. If you know when main.curr is set you might be able to trick the session. Here is a couple of things I have done in the past to get baan sessions to work on my 4c4 sytem - without having the code. Some of these are just plain old swags on what might work.

(1) You can try setting the variable main.ccur as external in the API code and exporting it. Seems like there was one session where I did something like this and it worked. Usually I end up importing into the baan session using qkey. Never hurts to try, but doubt it will work.

(2) Try a stpapi.update(session, 0, err.mesg) followed by the stpapi.save or stpapi.insert. I know one time I had to run the update with 0(false so no update occurs) followed by a stpapi.save. This worked for me on one session.

(3) Don't want to change the session code - how about adding an invisible field on the form for main.ccur? Then you can try using stpapi.put with main.ccur as the form field. Plus it really does not change the original session.

(4) Try using insert twice in a row. This is just a shot in the dark. While you don't want to change the original program you might what to put the session in debug mode - just to see what happens, when events get called or don't get called.

(5) Heck This is actual code from one of my sessions:
stpapi.save(sess.gld1101,e.msg)
stpapi.put.field(sess.gld1101, "tfgld101.ttyp", "CTR")
rc = stpapi.insert(sess.gld1101, 1, e.msg)

Notice I do a save first. That gets the session into a mode I can control and then I do the put fields and then an insert. Again pure swag.

(6) And last - what happens if you do not put the field tfcmg968.ccur at all? Does it default to something workable. In my maintain purchase order headers I can update everything except for one field on the form - what I did was insert all the fields on the session except for field with issues. Do an insert. Then I run a direct datebase update on this field.

rc = stpapi.insert( "tdpur4101m000", 1, msg )
if(strip$(msg)<>"" and strip$(msg)<>"Command cancelled") then
msg = sprintf$("Error insert: %s",msg)
stpapi.end.session( "tdpur4101m000" )
return(0)
endif
| You must save the record before getting the PO Number
rc = stpapi.save( "tdpur4101m000", msg )
if(strip$(msg)<>"") then
msg = sprintf$("Save PO: %s",msg)
stpapi.end.session( "tdpur4101m000" )
return(0)
endif

stpapi.get.field( "tdpur4101m000", "tdpur040.orno", some.field )
created.po = val(some.field)
| IF buyer did not update correctly update it here.
stpapi.get.field( "tdpur4101m000", "tdpur040.ccon", some.field )
buyer = val(some.field)
if buyer = 0 then
db.retry.point()
select tdpur040.*
from tdpur040 for update
where tdpur040._index1 = {:created.po}
as set with 1 rows
selectdo
tdpur040.ccon = po.buyer
db.update(ttdpur040,db.retry)
endselect
commit.transaction()
endif

mig28mx
28th February 2014, 03:51
Hi Mark,
I have choosed to fix the ccur variable to force a valid value.
After this, the program worked.

Thank you.