minadursun
13th March 2015, 15:20
In Infor ERP-LN 10.4 when I created a patch then bank transaction, I want to import lots of advance payment lines from *.csv file to the Transactions (tfgld1101m000) session.

I started the tfgld1101m000 and added a new batch and new transaction type (bank transaction), then run "Transaction Entry -enter.transactions-" form command. Actually this command is on the menu of the tfgld1101m100 Transaction Types session.

After then Bank Transactions (tfcmg2500m000) session is started via this command. I wanna insert my advance payment lines on this session. On the menu, there is a form command that is Insert -insert.in.details.mode-. Via this command, Bank Transactions session (tfcmg2500m000) is running again with different design -On fp3 from tfgld1101m000, I had got tfcmg2100s000 session screen and that looked like tfcmg2500m000-.

Here is my code below:




#pragma used dll ottstpapihand
#define MAIN.SESSION "tfgld1101m100"
#define SUB.SESSION "tfcmg2500m000"

function void doit()
{
boolean tmp.first
long afs.ret

afs.ret = 0
error.msg = ""

stpapi.put.field(MAIN.SESSION, "tfgld101.year", str$(year.f))
stpapi.put.field(MAIN.SESSION, "tfgld101.btno", str$(btno.f))
stpapi.put.field(MAIN.SESSION, "tfgld101.ttyp", ttyp.f)
afs.ret = stpapi.find(MAIN.SESSION, error.msg)
if afs.ret <> 1 then
fp.ret = seq.puts("Error: Could not find the record! ", fp.log)
stpapi.end.session(MAIN.SESSION, error.msg)
return
endif
afs.ret = stpapi.mark(MAIN.SESSION, error.msg)
if afs.ret <> 1 then
fp.ret = seq.puts("Error: Could not mark the record! ", fp.log)
stpapi.end.session(MAIN.SESSION, error.msg)
return
endif


stpapi.handle.subproc(MAIN.SESSION, SUB.SESSION, "add", error.msg)

stpapi.form.command(MAIN.SESSION, 2, "enter.transactions", error.msg)

stpapi.form.command(SUB.SESSION, 2, "insert.in.details.mode", error.msg)
if afs.ret = 0 then
message(error.msg)
stpapi.end.session(MAIN.SESSION, error.msg)
return
endif

tmp.first = true
while seq.gets(buffer, MAX.STR, fp.import) = 0
if process.records.from.file() = NUMBER.OF.FIELDS then
create.record(tmp.first)
tmp.first = false
else
fp.ret = seq.puts(buffer & "Data is corrupt " , fp.log)
endif
endwhile
stop.all.processes()
}

function long process.records.from.file()
{

fields.scanned = string.scan(buffer, "%s,%s,%s,%f", prm.bpid, prm.bpnm, prm.bpac, prm.amnt)
return(fields.scanned)
}


function create.record(boolean first.i)
{
long afs.ret
string tmp.str(MAX.STR) mb

stpapi.put.field(SUB.SESSION, "tfcmg204.year", str$(year.f))
stpapi.put.field(SUB.SESSION, "tfcmg204.btno", str$(btno.f))
stpapi.put.field(SUB.SESSION, "tfcmg204.ttyp", str$(ttyp.f))
stpapi.put.field(SUB.SESSION, "tfcmg204.docd", str$(docd.f))
stpapi.put.field(SUB.SESSION, "tfcmg204.docn", str$(seri.f))
stpapi.put.field(SUB.SESSION, "tfcmg204.lino", "1")
stpapi.put.field(SUB.SESSION, "tfcmg204.tran", str$(tfcmg.tran.advance.paym))
stpapi.put.field(SUB.SESSION, "tfcmg204.bpid", prm.bpid)
stpapi.put.field(SUB.SESSION, "tfcmg204.ccur", ccur.f)
stpapi.put.field(SUB.SESSION, "tfcmg204.amnt", str$(prm.amnt))
prm.bpnm = referance.f & " " & prm.bpnm
stpapi.put.field(SUB.SESSION, "tfcmg204.refr", prm.bpnm)
afs.ret = stpapi.insert(SUB.SESSION, true, error.msg)
if afs.ret = 0 then
tmp.str = "Error: " & buffer & " Message: " & mb.cast.to.str$(error.msg)
fp.ret = seq.puts(tmp.str, fp.log)
afs.ret = stpapi.recover(SUB.SESSION, error.msg)
endif

}

function generate.tmp.file.names()
{
long r_number

r_number = random()

remote.file.name = getenv$("BSE") & "/tmp/import_items_uploaded_" & str$(r_number) & ".txt"
log.file.name = getenv$("BSE") & "/tmp/import_items_log_" & str$(r_number) & ".txt"
}

function stop.all.processes()
{
stpapi.end.session(SUB.SESSION, error.msg)
stpapi.end.session(MAIN.SESSION, error.msg)
}




My *.csv file format is below:

123456,Mark Smith,666666,128.6
654321,Alice Silver,5555555,32.51


First column is Business Partner ID,
Second column is BP name,
Third one is bank account
Fourth one is amount.

My problem is that,
On fp3 my main session was tfgld1101m000 and this program was working very vell. I change it with tfgld1101m100 on 10.4. It works but one line is added, next one is not.
For example if I have 10 lines, the program added only 5 lines and these are 1., 3., 5., 7., 9. ones.

I could not understand why. Please share your experience and thoughts with me.

Thanks in advance.

Mina

bhushanchanda
15th March 2015, 22:28
Hi,

First thing to check will be the data. Check if you are manually able to insert the records.

If the data is OK, you can try using suspend() function after your insert (or after one of the form commands which is taking more time to execute). Something like suspend(500) will be fine.

May be the first record is taking time to save as with 10.4 the number of DAL hooks and dependencies have increased.

sghatge
14th May 2019, 06:05
I have also some AFS issue for session tfcmg2500m000. when I set the series "1905" for field tfcmg204.docn but system is taking first or last series internally in LN 10.4 version.

Anybody can know this issue then please correct me.

SG

mark_h
14th May 2019, 14:55
Post your code maybe someone will see something. Do you own source where you could debug what tfcmg2500m000 is doing?

sghatge
14th May 2019, 17:22
Please find code below for version LN10.4. you can use variables as you wish for testing purpose. Actual issue is for set document number field i.docn at the time of inserting record. it is not set as is set "1905". I am using transaction type "B21" and month wise series "yymm". there are so may series we have maintained in the series table. for e.g first series is "1305" and last default series is "9999". I am trying to using series "1905" but in AFS it is always taking "9999". if I am blocking "9999" then it is taking first series "1305" but not taking I defined "1905". all other fields are set ok.

domain tfgld.btno m.btno
bref.f = "S-" & logname$ & "-" & str$(tfvir316.bpid)
message("Generating Batch for date " & sprintf$("%D(%02d/%02m/%4Y)", m.dt))
|create batch (tfgld1101m000) ================================
stpapi.put.field("tfgld1101m000", "tfgld100.tedt", str$(m.dt))
stpapi.put.field("tfgld1101m000", "tfgld100.bref", bref.f)
result = stpapi.insert("tfgld1101m000", true, err.mess)
if result <> 0 and isspace(err.mess) then
stpapi.get.field("tfgld1101m000", "tfgld100.year", m.val)
f.year = lval(m.val)
stpapi.get.field("tfgld1101m000", "tfgld100.btno", m.val)
m.btno = lval(m.val)

stpapi.put.field("tfgld1101m100", "tfgld101.year", str$(f.year))
stpapi.put.field("tfgld1101m100", "tfgld101.btno", str$(m.btno))
result = stpapi.change.view("tfgld1101m100", err.mess)
stpapi.put.field("tfgld1101m100", "tfgld101.ttyp",tfvir316.otyp)
result = stpapi.insert("tfgld1101m100", true, err.mess)
if result = 0 then
b.exit = 1
while true
stpapi.get.mess.code("tfgld1101m000", err.mess)
if isspace(err.mess) then
break
endif
logline("Create Batch Message : " & err.mess)
endwhile
endif
if b.exit = 1 then
stpapi.end.session("tfgld1101m000")
GOTO GOTERR
endif
|stpapi.get.field( "tfgld1101m000", "tfgld101.btno", m.val)
logline("Created Batch No : " & str$(m.btno))


stpapi.put.field( "tfgld1101m100", "tfgld101.year", str$(f.year))
stpapi.put.field( "tfgld1101m100", "tfgld101.btno", str$(m.btno))
stpapi.put.field( "tfgld1101m100", "tfgld101.ttyp", tfvir316.otyp)
result = stpapi.find("tfgld1101m100", err.mess)
result = stpapi.mark("tfgld1101m100", err.mess)
stpapi.handle.subproc( "tfgld1101m100", "tfcmg2500m000", "add" )
stpapi.form.command( "tfgld1101m100", 5, "enter.transactions", err.mess )

domain tcamnt m.cram, m.rmam, m.oram
domain tcorno m.sono
m.lino = 1

if m.lino = 1 then
stpapi.put.field( "tfcmg2500m000", "tfcmg204.docn", str$(i.docn))
endif

|stpapi.put.field( "tfcmg2500m000", "tfcmg204.lino", str$(m.lino) )
utc.to.local(tfvir316.dodt, mD1, mD2)
stpapi.put.field( "tfcmg2500m000", "tfcmg204.docd", str$(mD1) )
stpapi.put.field( "tfcmg2500m000", "tfcmg204.ccur", p.ccur )
stpapi.put.field( "tfcmg2500m000", "tfcmg204.rate", str$(p.curt) )
m.tran = ltoe(6)
if p.ninv <> 0 then
m.tran = ltoe(1)
endif
stpapi.put.field( "tfcmg2500m000", "tfcmg204.tran", str$(m.tran) )
stpapi.put.field( "tfcmg2500m000", "tfcmg204.bpid", p.bpid )
if p.ninv <> 0 then
stpapi.put.field( "tfcmg2500m000", "tfcmg204.tinv", p.ttyp )
stpapi.put.field( "tfcmg2500m000", "tfcmg204.ninv", str$(p.ninv) )
endif
stpapi.put.field( "tfcmg2500m000", "tfcmg204.amnt", str$(p.amnt) )
stpapi.put.field( "tfcmg2500m000", "tfcmg204.refr", p.refr)
stpapi.put.field( "tfcmg2500m000", "tfcmg204.vatc", "IND" )
stpapi.put.field( "tfcmg2500m000", "tfcmg204.cvat", "NOTAX")
result = stpapi.insert("tfcmg2500m000", true, err.mess)
suspend(500)
result = stpapi.save("tfcmg2500m000", err.mess)
if result = 0 then
b.exit = 1
while true
stpapi.get.mess.code("tfcmg2500m000", err.mess)
if isspace(err.mess) then
break
endif
logline("Create Document Message : " & err.mess)
endwhile
else
stpapi.get.field( "tfcmg2500m000", "tfcmg204.ttyp", o.ityp )
stpapi.get.field( "tfcmg2500m000", "tfcmg204.docn", m.val )
o.idoc = val(m.val)
stpapi.get.field( "tfcmg2500m000", "tfcmg204.lino", m.val )
o.ilin = val(m.val)
logline("Created Document No : " & o.ityp & " / " & str$(o.idoc) & " / " & str$(o.ilin))

stpapi.end.session("tfcmg2500m000")
stpapi.end.session("tfgld1101m100")
stpapi.end.session("tfgld1101m000")
endif

mark_h
14th May 2019, 21:03
Assuming you are only trying 1 transaction you can always try this:


result = stpapi.insert("tfcmg2500m000", false, err.mess)
suspend(500)
result = stpapi.save("tfcmg2500m000", err.mess)


What I would do to start with is right before the insert - do a get field on tfcmg204.docn to see what is in it. Do the insert with false, do a get field on tfcmg204.docn and see what is in it. Then do the save and again get the tfcmg204.docn to see what is in it. Everything I see looks okay from just glancing at it. We are on 4c4 and do not have this session.

sghatge
15th May 2019, 07:57
Hi Mark,
I have tried as you suggested but same thing happening. Still document generating with 9999 series as "9999xxxx".
Is there any other way?

mark_h
15th May 2019, 14:48
Did you check the variable before the insert and after the insert to see exactly when it changed from what you input? My suspicion is you put all the fields, but since you are running in API mode it does not hit all the normal events like it normally would. Then you do an insert and one of those events is changing the series on you. Again just a suspicion - without source code no way I know of to see exactly what is happening.

I know what I would do - but can speak for you. With LN you try DAL2 functionality to try to do something thing. I can't speak to that since we are on 4c4. What I would do on my 4c4 system (we do not own source code) I would make the session a qkey (source extender) type session. I would then add all the events into it and put it in debug mode. While I can't see actual code I could step thru it seeing exactly what event or actions might be occurring to change the series. So for example if I saw when I hit the insert command it hit the after.input of tfcmg204.docn and it changed it then, I could always work around that event with qkey. I could say if not api.mode then run normally otherwise skip this event.