psuryava
21st November 2013, 08:56
Hi
I am trying to automate session tfgld1101m000 & tfacp1110s000 using afs, but I am not able to insert record in table tfacp200.
When I run the afs code and debug session tfacp1110s000, I noticed that event
choice.add.set --> before.choice is triggered on stpapi.insert() call.
After this the sub-session populates and calculates all the required values for tfacp200, but record is not inserted/saved !!
The control returns back to afs code with err message "Session not available".
The record is not inserted because, the main.table.io sections, before.write and after.write in session tfacp1110s000 are not executed.
I have already checked and confirmed that all required values for tfacp200 are populated through afs.
I have tried to set "do.save" flag to 0/1 in stpapi.insert() and tried calling stpapi.save() after it. But record is not inserted.
Any idea why this can be happening?
Thanks in advance.
bhushanchanda
21st November 2013, 10:08
Hi,
If possible please post your code. That will be give a better idea to others.
Also do a search on board. There are many similar threads.
Here is a solved thread:-
Thread (http://www.baanboard.com/baanboard/showthread.php?p=87135)
psuryava
21st November 2013, 12:25
| Maintain batch
stpapi.put.field("tfgld1101m000", "tedt.f", str$(tedt.i))
stpapi.put.field("tfgld1101m000", "bref.f", bref.i)
| Switch the view
err.cde = stpapi.change.view("tfgld1101m000")
if FAIL then
err.msg = "View not found"
message(err.msg)
endif
stpapi.put.field("tfgld1101m000", "tfgld101.ttyp", ttyp.i)
| Insert Transaction
stpapi.insert("tfgld1101m000", true, err.msg)
if FAIL then
message(err.msg)
stpapi.recover("tfgld1101m000", err.msg)
endif
| Maintain transaction
stpapi.get.field("tfgld1101m000", "tfgld101.btno", value)
batch.no = lval(value)
message("Batch Number is %d", batch.no)
err.cde = stpapi.browse.set("tfgld1101m000", "last.set")
if NOT_FOUND then
err.msg = "Maintained transaction not found"
message(err.msg)
endif
err.cde = stpapi.browse.set("tfgld1101m000", "mark.occur")
if FAIL then
err.msg = "error in mark"
message(err.msg)
endif
stpapi.handle.subproc("tfgld1101m000", "tfacp1110s000", "add")
stpapi.continue.process("tfgld1101m000", err.msg)
if FAIL then
message(err.msg)
stpapi.recover("tfgld1101m000", err.msg)
endif
stpapi.put.field("tfacp1110s000", "tfacp200.suno", suno.i)
stpapi.put.field("tfacp1110s000", "tfacp200.docd", str.date)
stpapi.put.field("tfacp1110s000", "tfacp200.ccur", ccur.i)
stpapi.put.field("tfacp1110s000", "screen.amnt", str$(amnt.i))
stpapi.put.field("tfacp1110s000", "tfacp200.cvat", cvat.i)
stpapi.put.field("tfacp1110s000", "screen.vata", str$(taxm.i))
stpapi.put.field("tfacp1110s000", "tfacp200.isup", isup.i)
stpapi.put.field("tfacp1110s000", "tfacp200.refr", isup.i & " ASD TEST")
stpapi.put.field("tfacp1110s000", "tfacp200.bloc", bloc.i)
stpapi.put.field("tfacp1110s000", "tfacp200.bdat", str.date)
stpapi.put.field("tfacp1110s000", "tfacp200.bref", bref.i)
stpapi.put.field("tfacp1110s000", "tfacp200.loco", str$(get.compnr()))
stpapi.put.field("tfacp1110s000", "tfacp200.cpay", cpay.i)
stpapi.put.field("tfacp1110s000", "tfacp200.dued", str.date)
stpapi.put.field("tfacp1110s000", "tfacp200.paym", paym.i)
stpapi.put.field("tfacp1110s000", "tfacp200.bank", bank.i)
stpapi.put.field("tfacp1110s000", "tfacp200.btno", str$(batch.no))
stpapi.handle.subproc("tfacp1110s000", "tfacp1130s000", "add")
stpapi.insert("facp1110s000", true, err.msg)
stpapi.save("tfac1110s000",err.msg)
if FAIL then
message(err.msg)
stpapi.recover("tfacp1110s000", err.msg)
stpapi.end.session("tfacp1130s000")
stpapi.end.session("tfacp1110s000")
stpapi.end.session("tfgld1101m000")
endif
stpapi.end.session("tfacp1130s000")
stpapi.end.session("tfacp1110s000")
stpapi.end.session("tfgld1101m000")
bhushanchanda
21st November 2013, 13:25
Hi,
Is it working fine now? Or still causing issues? Have you looked at the mentioned thread?
psuryava
21st November 2013, 13:39
Yes i looked at the thread mentioned by you.
The error was still not resolved.
on stpapi.insert() --> in session tfacp1110s000, choice.add.set--> before.choice is invoked and after that nothing is processed in the sub-session.
the control comes back to afs with error --"Session not available".
I have posted the code for reference
bhushanchanda
21st November 2013, 13:58
Hi,
You code looks quite different from the one posted in the thread. Well right now cant think of the error. Will run a test against your code and will see if I get something.
mark_h
21st November 2013, 15:39
Is this a typo in the code or in the post "stpapi.insert("facp1110s000", true, err.msg)"? Note it should be tfacp1110s000.
mark_h
21st November 2013, 15:41
Same for stpapi.save("tfac1110s000",err.msg). Missing the p in tfacp.
psuryava
22nd November 2013, 05:30
yes it is a typo error while pasting the code
mark_h
22nd November 2013, 05:51
Here is my code from one session that does work. I attack it a little differently than you do. Not sure this will work for you - there could be differences in libraries and objects.
Function process.selected.date()
{
sel.date = tfudi030.date
sel.ttyp = tfudi030.ttyp
| Added just because the user might get cute and try to process a Transaction
| type thru the session that it is not designed for.
if sel.ttyp<>"APG" and sel.ttyp<>"APD" then
message("Transaction type not defined by program.")
return
endif
| Create batch - note subroutine leaves the two tfgld sessions open
if api.create.batch() then
stpapi.end.session("tfgld1101s000")
stpapi.end.session("tfgld1100m000")
return
endif
|Start processing the data selected.
select a.srno:sel.srno
from tfudi030 a
where a._index1 = {:sel.date, :sel.ttyp}
selectdo
db.retry.point()
select tfudi030.*
from tfudi030 for update
where tfudi030._index1 = {:sel.date, :sel.ttyp, :sel.srno}
as set with 1 rows
selectdo
| 20080207.st Reverse the oncase statement since get.max.refr needs tiudi035.pref
| to already be set.
| Did a case statement because they might add transaction types later.
on case sel.ttyp
case "APG":
tfudi035.pref = "G"
break
case "APD":
tfudi035.pref = "D"
break
endcase
sel.refr = get.max.refr() | 20080207.en
api.create.invoice()
if isspace(e.msg) then
tfudi035.date = sel.date
tfudi035.ttyp = tfudi030.ttyp
tfudi035.srno = get.max.srno()
tfudi035.suno = tfudi030.suno
tfudi035.isup = tfudi030.isup
tfudi035.reas = tfudi030.reas
tfudi035.leac = tfudi030.leac
tfudi035.amnt = tfudi030.amnt
tfudi035.refr = sel.refr
tfudi035.dtep = date.num()
tfudi035.btno = sel.btno
tfudi035.user = logname$
db.insert(ttfudi035)
db.delete(ttfudi030,db.retry)
else
tfudi030.err = e.msg
db.update(ttfudi030,db.retry)
endif
endselect
commit.transaction()
endselect
stpapi.end.session("tfgld1101s000")
stpapi.end.session("tfgld1100m000")
}
function domain tcorno get.max.srno()
{
domain tcorno max.srno
max.srno = 0
select max(a.srno):max.srno
from tfudi035 a
where a._index1 = {:sel.date, :sel.ttyp}
selectdo
endselect
max.srno = max.srno + 1
return(max.srno)
}
| Reference number must be unique
function domain tcorno get.max.refr()
{
domain tcorno max.refr
select max(a.refr):max.refr
from tfudi035 a
where a.pref = :tfudi035.pref
selectdo
selectempty
max.refr = 9999
endselect
max.refr = max.refr + 1
return(max.refr)
}
function api.create.invoice()
{
domain tcmcs.str80 hold.msg
|Active the tfacp1110s000 session.
stpapi.continue.process("tfgld1101s000", e.msg)
| Clear insert mode.
stpapi.save("tfacp1110s000",e.msg)
| Add the new record - note isup and refr must be unique on our system.
stpapi.put.field("tfacp1110s000", "tfacp200.suno", strip$(tfudi030.suno))
stpapi.put.field("tfacp1110s000", "tfacp200.isup", str$(tfudi030.isup))
stpapi.put.field("tfacp1110s000", "tfacp200.docd", str$(date.num()))
stpapi.put.field("tfacp1110s000", "tfacp200.refr", tfudi035.pref & str$(sel.refr))
stpapi.put.field("tfacp1110s000", "screen.amnt", str$(round(tfudi030.amnt, 2, 0)))
stpapi.put.field("tfacp1110s000", "tfacp200.reas", tfudi030.reas )
stpapi.handle.subproc("tfacp1110s000", "tfacp1120s000", "add")
rc = stpapi.insert("tfacp1110s000", 1, e.msg)
if not isspace(e.msg) then
stpapi.end.session("tfacp1110s000")
return
endif
|Insert the account on tfacp1120s000
stpapi.put.field("tfacp1120s000", "tfgld102.leac", tfudi030.leac)
rc = stpapi.insert("tfacp1120s000", 1, e.msg)
if not isspace(e.msg) then
stpapi.end.session("tfacp1120s000")
hold.msg = e.msg
stpapi.delete("tfacp1110s000", true, e.msg)
e.msg = hold.msg
stpapi.end.session("tfacp1110s000")
return
endif
| End the two sessions
stpapi.end.session("tfacp1120s000")
stpapi.end.session("tfacp1110s000")
}
function long api.create.batch()
{
| tfgld1100m000 (Maintain Transactions)
| Put data and create batch
stpapi.put.field("tfgld1100m000", "tfgld100.tedt", str$(date.num()))
stpapi.put.field("tfgld1100m000", "tfgld100.bref", sprintf$("Garnishments %D(%02m/%02d/%02y)", date.num()))
rc = stpapi.insert("tfgld1100m000", 1, e.msg)
if not isspace(e.msg) then
message("Unable to create transaction type.")
return(true)
endif
| Get the batch created.
stpapi.get.field("tfgld1100m000","tfgld100.btno",e.msg)
sel.btno = val(strip$(e.msg))
| Activate tfgld1101s000 subsession
stpapi.handle.subproc("tfgld1100m000", "tfgld1101s000", "add")
stpapi.continue.process("tfgld1100m000", e.msg)
| Clear the input mode the session starts in
stpapi.save("tfgld1101s000",e.msg)
| Put the transaction type
stpapi.put.field("tfgld1101s000", "tfgld101.ttyp", strip$(tfudi030.ttyp))
rc = stpapi.insert("tfgld1101s000", 1, e.msg)
if not isspace(e.msg) then
message("Unable to create transaction type.")
return(true)
endif
return(false)
}
psuryava
22nd November 2013, 07:03
thanks Mark,
Will try to check with my code
psuryava
23rd November 2013, 08:53
Thanks for your help.
the issue was resolved !
mark_h
24th November 2013, 22:27
What was the solution if you don't mind?