tmannais
4th September 2018, 11:04
Hi,

I have been trying to use AFS to print a report but it just doesn't seem to work.
Here is the code:

function print.material.shortages()
{
string session.code(13)
domain tdcrm.emsg error.msg

error.msg = ""
session.code = PRINT.MATERIAL.SHORTAGES.SESSION
|stpapi.put.field(session.code, "grid.f", "")
|stpapi.put.field(session.code, "grid.t", "ZZZZZZZZZ")
stpapi.put.field(session.code, "pdno.f", str$(production.order))
stpapi.put.field(session.code, "pdno.t", str$(production.order))
|stpapi.put.field(session.code, "date.f", "")
|stpapi.put.field(session.code, "date.t", "01/19/2038")
|stpapi.put.field(session.code, "plid.f", "")
|stpapi.put.field(session.code, "plid.t", "ZZZZZZZZZ")
|stpapi.put.field(session.code, "sfpl.f", "")
|stpapi.put.field(session.code, "sfpl.t", "ZZZZZZZZZ")
stpapi.set.report(session.code, "rtisfc041911000", "D", error.msg)
if not isspace(error.msg) then
error.msg = "Cannot set report Material Shortages: " & error.msg
message(error.msg)
endif
|stpapi.form.command(session.code, 5, "exec.cont.process", error.msg)
stpapi.print.report(session.code, error.msg)
if not isspace(error.msg) then
error.msg = "Cannot print report Material Shortages: " & error.msg
message(error.msg)
endif
message("Print Report!")
stpapi.end.session(session.code)
}

The session is "tisfc0419m000".

What I have tested/tried:
- production.order really has correct value
- stpapi.put.field to all the fields in the session
- stpapi.put.field to the only field I want to change
- stpapi.form.command with "exec.cont.process"
- stpapi.form.command with "print.data"
- stpapi.print.report
- add the report into the session

*** stpapi.print.report gives "Command Disabled" error while other methods give no errors but none of them actually print the report.

Please help.

Regards,
Thana

tmannais
4th September 2018, 11:58
The mystery has been solved. The problem doesn't relate to AFS.
Here is the working code for anyone who wants to know what it should be.

function print.material.shortages()
{
string session.code(13)
domain tdcrm.emsg error.msg
error.msg = ""
session.code = PRINT.MATERIAL.SHORTAGES.SESSION
stpapi.put.field(session.code, "pdno.f", str$(production.order))
stpapi.put.field(session.code, "pdno.t", str$(production.order))
stpapi.set.report(session.code, "rtisfc041911000", "D", error.msg)
if not isspace(error.msg) then
error.msg = "Cannot set report Material Shortages: " & error.msg
message(error.msg)
endif
stpapi.form.command(session.code, 5, "exec.cont.process", error.msg)
if not isspace(error.msg) then
error.msg = "Cannot print report Material Shortages: " & error.msg
message(error.msg)
endif
stpapi.end.session(session.code)
}

In this case, my problem comes from an Extension that calls this session; so, may this topic be closed.

mark_h
4th September 2018, 15:14
Glad you solved it and thanks for posting the solution. PS - my first guess would have been that date. I usually do things like stpapi.put.field("tdilc4401m000","prdt.t",str$(date.num()+1000)) :)