tmannais
20th March 2018, 11:51
Hi,

I am trying to print a report using AFS in LN 10.5.
This is what works for me for when the user wants to print all the data, which is likely never going to happen.

stpapi.set.report("tdsls4409m000", "rtdsls440901300", "PDF", error.msg)
message("Set Report: " & error.msg)
if isspace(error.msg) then
stpapi.form.command("tdsls4409m000", 5, "print.data", error.msg)
message("Print Report: " & error.msg)
endif
stpapi.end.session("tdsls4409m000", error.msg)


This is the code when I tried to put some values into the report before printing it. (The only field I put to is Sales Order for both from and to).

stpapi.put.field("tdsls4409m000", "ddta.f", "")
stpapi.put.field("tdsls4409m000", "ddta.f.time", "")
stpapi.put.field("tdsls4409m000", "ddta.t", "03/20/2018")
stpapi.put.field("tdsls4409m000", "ddta.t.time", "")
stpapi.put.field("tdsls4409m000", "cofc.f", "")
stpapi.put.field("tdsls4409m000", "cofc.t", "ZZZZZZ")
stpapi.put.field("tdsls4409m000", "ofbp.f", "")
stpapi.put.field("tdsls4409m000", "ofbp.t", "ZZZZZZZZZ")
stpapi.put.field("tdsls4409m000", "orno.f", "CSO001911")
stpapi.put.field("tdsls4409m000", "orno.t", "CSO001911")
stpapi.put.field("tdsls4409m000", "pono.f", "")
stpapi.put.field("tdsls4409m000", "pono.t", "9999")
stpapi.put.field("tdsls4409m000", "crep.f", "")
stpapi.put.field("tdsls4409m000", "crep.t", "ZZZZZZZZZ")
stpapi.put.field("tdsls4409m000", "ccur.f", "")
stpapi.put.field("tdsls4409m000", "ccur.t", "ZZZ")
stpapi.put.field("tdsls4409m000", "cofc.f", "")
stpapi.put.field("tdsls4409m000", "cofc.t", "ZZZZZZ")
stpapi.put.field("tdsls4409m000", "dltp.f", str$(etol(tdsls.dltp.not.applicable)))
stpapi.put.field("tdsls4409m000", "dltp.t", str$(etol(tdsls.dltp.production)))
stpapi.put.field("tdsls4409m000", "cprj.f", "")
stpapi.put.field("tdsls4409m000", "cprj.t", "ZZZZZZZZZ")
stpapi.put.field("tdsls4409m000", "cmnf.f", "")
stpapi.put.field("tdsls4409m000", "cmnf.t", "ZZZZZZ")
stpapi.put.field("tdsls4409m000", "cpln.f", "")
stpapi.put.field("tdsls4409m000", "cpln.t", "ZZZZZZ")
stpapi.put.field("tdsls4409m000", "cpcl.f", "")
stpapi.put.field("tdsls4409m000", "cpcl.t", "ZZZZZZ")
stpapi.put.field("tdsls4409m000", "creg.f", "")
stpapi.put.field("tdsls4409m000", "creg.t", "ZZZ")
stpapi.put.field("tdsls4409m000", "item.f.segment.1", "")
stpapi.put.field("tdsls4409m000", "item.f.segment.2", "")
stpapi.put.field("tdsls4409m000", "item.t.segment.1", "ZZZZZZZZZ")
stpapi.put.field("tdsls4409m000", "item.t.segment.2", "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
stpapi.set.report("tdsls4409m000", "rtdsls440901300", "PDF", error.msg)
message("Set Report: " & error.msg)
if isspace(error.msg) then
stpapi.form.command("tdsls4409m000", 5, "print.data", error.msg)
message("Print Report: " & error.msg)
endif
stpapi.end.session("tdsls4409m000", error.msg)


I tried setting only the Sales Order fields in from and to, and I also tried setting all of the fields like the code above. Both cases do not work.
There is no error whatsoever in the whole process but the report just does not show up/ save to file. I tried device "D" and "PDF" both have the same effect.

I just want to print using specific values in general because I will use in other reports too, not only Sales Order.

Regards,
Thana

tmannais
21st March 2018, 06:23
I figured it out. The problem is that the fields it takes for Sales Order are orno.f.segment.1 and orno.t.segment.1 instead of just orno.f and orno.t
like so


stpapi.put.field("tdsls4409m000", "orno.f.segment.1", str$(i.tdcrm411.orno))
stpapi.put.field("tdsls4409m000", "orno.t.segment.1", str$(i.tdcrm411.orno))
stpapi.set.report("tdsls4409m000", "rtdsls440901300", "PDF", error.msg)
message("Set Report: " & error.msg)
if isspace(error.msg) then
stpapi.form.command("tdsls4409m000", 5, "print.data", error.msg)
message("Print Report: " & error.msg)
endif
stpapi.end.session("tdsls4409m000", error.msg)

As a result, the report is printed correctly (PDF in this case).

However, this is somehow not yet generalized because I tried using similar code to this (changing only session code and fields) with other session that has many reports for user to select in order to print, but it just does not work. It returns no error but the report is not printed.
The problem, in my opinion, is on the report selection for the case when the print session has more than one report for the user to choose.
Is there a way for AFS to select a report out of it since the window for report selection does not have session code? I really have no idea how to tackle that with AFS.
See the attached image for the report selection window.

mark_h
21st March 2018, 14:15
The problem is you can out pick one report. So you use the stpapi.set.report pick one and run the session. On some in 4c4 if it generates 2 reports it might not work or even lock up. I think what I do for something like outbound I will generate the error report, then run the print outbound session to get a listing. We do that in several cases.

tmannais
22nd March 2018, 03:33
But I have already used stpapi.set.report as you can see in the code, and it is not working. I tried printing in the session myself manually and it prints only 1 report.

mark_h
22nd March 2018, 14:52
Have you tried a continue instead of print.data? you may also want to try the screen instead of the pdf device. The set command looks correct to me, which leads me to believe it could be something in one of the fields getting put to the screen. I am not on ln so I can't help a whole lot.

tmannais
23rd March 2018, 05:39
I have tried cont.process and exec.cont.process but no luck. I have also tried device D instead of PDF. Still, does not work.
In this session, I only put 2 fields similar to the code in #2 but they are Warehousing Orders instead, and that the session has many reports.

giggty
23rd March 2018, 09:08
tmannais, how come my whinh4460m000 has only one report (whinh446011000 Outbound Advice by Run)? Have you customized this session?

tmannais
23rd March 2018, 12:08
giggty, the session has been customized but it's not my doing. It just has the reports added in it, it seems. That's why it has many reports to select, and I still don't know if it is causing the issue.

giggty
23rd March 2018, 13:37
Ok, I've found another print session with two reports (whinh4478m000) and this code prints both reports:

stpapi.put.field("whinh4478m000", "all.orders", str$(tcyesno.yes))
stpapi.set.report("whinh4478m000", "rwhinh447811000", "D", error.msg)
message("Set Report: " & error.msg)
if isspace(error.msg) then
stpapi.form.command("whinh4478m000", 5, "exec.cont.process", error.msg)
message("Print Report1: " & error.msg)
endif
stpapi.set.report("whinh4478m000", "rwhinh447812000", "D", error.msg)
message("Set Report: " & error.msg)
if isspace(error.msg) then
stpapi.form.command("whinh4478m000", 5, "exec.cont.process", error.msg)
message("Print Report2: " & error.msg)
endif
stpapi.end.session("whinh4478m000", error.msg)

So your code seems to be perfectly valid. Try "exec.print.data" instead of "print.data", may be?

giggty
23rd March 2018, 14:37
I've generated the dll for whinh4460m000 in ttstpcreatdll. And for printing it uses stpapi.print.report(), and it works, I tested it :) stpapi.form.command() doesn't work probably because whinh4460m000 does not have a form command defined (whinh4478m000 has exec.cont.process which is why stpapi.form.command works for whinh4478m000), at least none of cont.process/print.data/exec/etc arguments I tried worked for me.

tmannais
30th March 2018, 07:00
Thank you for your help, giggty. I will try it out and will respond back if it works for me.