gget79
11th June 2009, 16:21
Hi Friends,

I am working with Infor LN 6.1

I am making a program that for api (AFS), it uses the session "Link Credit Notes to schedules - tfacr2122m000", but when I send a search for api to this session, it doesn't work for me, my source code is the following:


function extern domain tcbool lesls.dll0003.aplica.ventas(domain tfgld.year l.year, domain tfgld.btno l.btno, domain tfgld.ttyp l.ttyp)
{
domain tcbool f.ventas
domain tfgld.long retval
domain tfgld.long ret
domain tfgld.long i
domain tfgld.long j
domain tfgld.long retaux
domain tcmcs.str215 error.msg
domain tfgld.ttyp l.tdra
domain tfgld.amnt l.tret
domain tccom.bpid l.bpid
domain tcncmp l.cia
domain tcyesno l.prog
domain tfgld.ninv l.nina
domain tfgld.ninv l.ninv(100)
domain tcmcs.str16 fecha.doc
long puntero_tfacr200
string buf.ttfacr200(2048)
i = 1
j = 0
m.rtyp = ""
l.cia = get.compnr()
puntero_tfacr200 = db.bind("ttfacr200", buf.ttfacr200)
db.columns.to.record(puntero_tfacr200)
select tfacr200.ninv
from tfacr200
where tfacr200._index3 = {:l.year,:l.btno,:l.ttyp}
and tfacr200.tdoc = ""
and tfacr200.docn = 0
and tfacr200.lino = 0
selectdo
l.ninv(i) = tfacr200.ninv
i = i + 1
endselect
db.record.to.columns(puntero_tfacr200)
db.unbind(puntero_tfacr200)
for i = 1 to 100
if l.ninv(i) <> 0 then
|* Encuentro el lote al que voy a aplicar la nota de venta
stpapi.put.field("tfgld1101m000","tfgld101.year",str$(l.year))
stpapi.put.field("tfgld1101m000","tfgld101.btno",str$(l.btno))
retval = stpapi.find("tfgld1101m000",error.msg)
if retval = 1 then
|* Encuentro el tipo de transacción que aplica la nota de venta
dal.start.business.method("lepar000","give.tdra",retval,l.cia,l.tdra)
stpapi.put.field("tfgld1101m000","tfgld101.ttyp",str$(l.tdra))
retval = stpapi.find("tfgld1101m000",error.msg)
if retval <> 1 then
|* Inserto el tipo de transacción que aplica la nota de venta
stpapi.put.field("tfgld1101m000","tfgld101.ttyp",str$(l.tdra))
retval = stpapi.insert("tfgld1101m000",true,error.msg)
if retval <> 1 then
retaux = stpapi.recover("tfgld1101m000",error.msg)
f.ventas = false
stpapi.end.session("tfgld1101m000")
endif
endif
if retval = 1 then
stpapi.put.field("tfgld1101m000","tfgld101.ttyp",str$(l.tdra))
retval = stpapi.find("tfgld1101m000",error.msg)
if retval = 1 then
retval = stpapi.mark("tfgld1101m000",error.msg)
|* Encuentro el registro insertado
if retval = 1 then
stpapi.form.command("tfgld1101m000",1,"exec.cont.process",error.msg)
|* Para cada registro atado al lote y período fiscal, busco el partner y el tipo de transacción
dal.start.business.method("lesls006","give.bpid",retval,l.ttyp,l.ninv(i),0,l.bpid)
stpapi.put.field("tfacr2120m000","form.itbp",str$(l.bpid))
stpapi.put.field("tfacr2120m000","tfacr200.itbp",str$(l.bpid))
stpapi.put.field("tfacr2120m000","tfacr200.ttyp",str$(l.ttyp))
stpapi.put.field("tfacr2120m000","tfacr200.ninv",str$(l.ninv(i)))
retval = stpapi.find("tfacr2120m000",error.msg)
if retval = 1 then
|* Si lo encuentra busco el número de documento
stpapi.put.field("tfacr2120m000","tfacr200.ttyp",str$(l.ttyp))
stpapi.put.field("tfacr2120m000","tfacr200.ninv",str$((l.ninv(i))))
retval = stpapi.find("tfacr2120m000",error.msg)
if retval = 1 then
l.nina = l.ninv(i)
tiene.prog(l.ttyp,(l.ninv(i)), l.prog)
select lesls007.rtyp, lesls007.rnin, sum(lesls007.iret):l.tret
from lesls007
where lesls007._index1 = {:l.ttyp, :l.nina}
group by lesls007.rtyp, lesls007.rnin
selectdo
j = j + 1
m.rtyp = lesls007.rtyp
m.rninv = str$(lesls007.rnin)
if l.prog = tcyesno.no then
|* Si lo encuentra ejecuto Asignar notas de abono a factura
stpapi.form.command("tfacr2120m000",1,"start.second.session",error.msg)
|* Busco el documento al cual voy a afectar
stpapi.put.field("tfacr2121m000","tfacr200.bpid",str$(l.bpid))
stpapi.put.field("tfacr2121m000","tfacr200.ttyp",str$(lesls007.rtyp))
stpapi.put.field("tfacr2121m000","tfacr200.ninv",str$(lesls007.rnin))
ret = stpapi.find("tfacr2121m000",error.msg)
if ret = 1 then
ret = stpapi.mark("tfacr2121m000", error.msg)
if ret = 1 then
|* Si lo encuentro actualizo el valor de la retención.
stpapi.put.field("tfacr2121m000", "tfacr200.lamt",str$(l.tret))
ret = stpapi.update("tfacr2121m000", true, error.msg)
if trim$(error.msg) = "" then
stpapi.form.command("tfacr2121m000",1,"exec.cont.process",error.msg)
if j = 1 then
stpapi.form.command("tfcmg2114s000",1,"user.1",error.msg)
endif
f.ventas = true
else
f.ventas = false
break
endif
else
f.ventas = false
break
endif
else
f.ventas = false
break
endif
endif
if l.prog = tcyesno.yes then
l.nina = l.ninv(i)
stpapi.form.command("tfacr2120m000",1,"start.schedules.session",error.msg)
|* Busco el documento al cual voy a afectar
| stpapi.put.field("tfacr2122m000","main.bpid",str$(l.bpid))
stpapi.put.field("tfacr2122m000","tfacr201.ttyp",str$(lesls007.rtyp))
stpapi.put.field("tfacr2122m000","tfacr201.ninv",str$(lesls007.rnin))
stpapi.put.field("tfacr2122m000","tfacr201.schn",str$(1))
ret = stpapi.find("tfacr2122m000",error.msg)
if ret = 1 then
ret = stpapi.mark("tfacr2122m000",error.msg)
stpapi.put.field("tfacr2122m000","tfacr201.lamt",str$(l.tret))
ret = stpapi.update("tfacr2122m000",true,error.msg)
if ret <> 1 then
ret = stpapi.update("tfacr2122m000",true,error.msg)
if ret <> 1 then
ingresa.tfacr201(lesls007.rtyp,lesls007.rnin,fecha.doc,l.tret)
endif
endif
else
ingresa.tfacr201(lesls007.rtyp,lesls007.rnin,fecha.doc,l.tret)
ret = stpapi.find("tfacr2122m000",error.msg)
endif
if trim$(error.msg) = "" then
stpapi.form.command("tfacr2122m000",1,"exec.cont.process",error.msg)
if j = 1 then
stpapi.form.command("tfcmg2114s000",1,"user.1",error.msg) |get utilizar subproc
endif
f.ventas = true
else
f.ventas = false
break
endif
else
f.ventas = false
break
endif
endselect
j = 0
endif
if retval <> 1 then
retval = stpapi.recover("tfacr2120m000",error.msg)
stpapi.end.session("tfacr2120m000")
stpapi.end.session("tfgld1101m000")
f.ventas = false
endif
if not f.ventas then
if l.prog = tcyesno.no then
retval = stpapi.recover("tfacr2121m000",error.msg)
stpapi.end.session("tfacr2121m000")
endif
if l.prog = tcyesno.yes then
retval = stpapi.recover("tfacr2122m000",error.msg)
stpapi.end.session("tfacr2122m000")
endif
endif
stpapi.end.session("tfacr2120m000")
stpapi.end.session("tfgld1101m000")
else
retval = stpapi.recover("tfacr2120m000",error.msg)
stpapi.end.session("tfacr2120m000")
stpapi.end.session("tfgld1101m000")
f.ventas = false
endif
else
retval = stpapi.recover("tfgld1101m000",error.msg)
stpapi.end.session("tfgld1101m000")
f.ventas = false
endif
else
retval = stpapi.recover("tfgld1101m000",error.msg)
stpapi.end.session("tfgld1101m000")
f.ventas = false
endif
else
retval = stpapi.recover("tfgld1101m000",error.msg)
stpapi.end.session("tfgld1101m000")
f.ventas = false
endif
else
retval = stpapi.recover("tfgld1101m000",error.msg)
stpapi.end.session("tfgld1101m000")
f.ventas = false
endif
else
break
endif
endfor

for i = 1 to 100
l.ninv(i) = 0
| i = i +1
endfor

return(f.ventas)
}


Anybody can help me?

Thank you

mark_h
11th June 2009, 17:02
Well first on LN they recommend using Dal2 functionality.

Second is this the code not working:

stpapi.form.command("tfacr2120m000",1,"start.schedules.session",error.msg)
|* Busco el documento al cual voy a afectar
stpapi.put.field("tfacr2122m000","tfacr201.ttyp",str$(lesls007.rtyp))
stpapi.put.field("tfacr2122m000","tfacr201.ninv",str$(lesls007.rnin))
stpapi.put.field("tfacr2122m000","tfacr201.schn",str$(1))
ret = stpapi.find("tfacr2122m000",error.msg)

Can you confirm that the form command is working? In debug mode make sure that the form command starts session tfacr2122m000. Also make sure that the process ID for tfacr2122m000 has a parent process that is tfacr2120m000. If that does not work then the first put field will start tfacr2122m000, but it will not be tied correctly to the parent session.