vineetu1
11th November 2005, 09:02
I am in process of automating Sales order creation to printing of invoices.

I have written the following code for executing session tdsls4404m000 "Print Sales Invoice" which when executed with the option "Final Invoices = Yes" generates an invoice no.

I have tried using both the functions i.e. stpapi.continue.process() and stpapi.print.report with stpapi.set.report().

When I use stpapi.continue.process() I get the message no data within selection. When I use stpapi.set.report() it does not give any message but the invoice not is not getting generated.


declaration:
#pragma used dll ottstpapihand

table ttdsls045 | Sales Deliveries

extern domain tcorno sales.order.no |
extern domain tcdate inv.date |
string error.message(100)
string invoice.date(10)
string sales.order.number(6)
string company.number(3)

choice.cont.process:
on.choice:
process.print.sales.order()

functions:

function process.print.sales.order()
{

select tdsls045.*
from tdsls045
where tdsls045._index1 = {:sales.order.no}
and tdsls045.ssls = 6
as set with 1 rows
selectdo
print.sales.invoices()
selectempty
message("No records present")

endselect

}


function print.sales.invoices()

{

initalize.vars()

error.message = ""

invoice.date = str$(num.to.date$(date.num(),3))
| message("%s",invoice.date)
sales.order.number = str$(sales.order.no)
company.number = str$(get.compnr())


stpapi.put.field("tdsls4404m000", "printed", "No")
stpapi.put.field("tdsls4404m000", "inv.date", invoice.date)
stpapi.put.field("tdsls4404m000", "selection", "No")
stpapi.put.field("tdsls4404m000", "comp.f", company.number)
stpapi.put.field("tdsls4404m000", "comp.t", company.number)
stpapi.put.field("tdsls4404m000", "cuno.f", "")
stpapi.put.field("tdsls4404m000", "cuno.t", "ZZZZZZ")
stpapi.put.field("tdsls4404m000", "orno.f", sales.order.number)
stpapi.put.field("tdsls4404m000", "orno.t", sales.order.number)
stpapi.put.field("tdsls4404m000", "cotp.f", "")
stpapi.put.field("tdsls4404m000", "cotp.t", "ZZZ")
stpapi.put.field("tdsls4404m000", "amount.f", "-99999999")
stpapi.put.field("tdsls4404m000", "amount.t", "999999999")
stpapi.put.field("tdsls4404m000", "definite", "Yes")
stpapi.put.field("tdsls4404m000", "direct.process", "No")
stpapi.put.field("tdsls4404m000", "totals", "No")
stpapi.put.field("tdsls4404m000", "prnt.options", "No")
stpapi.put.field("tdsls4404m000", "prnt.sellpr", "No")
stpapi.set.report("tdsls4404m000", "rtdsls440401000","D",error.message)
if isspace(error.message) then
| stpapi.continue.process("tdsls4404m000", error.message)
stpapi.print.report("tdsls4404m000", error.message)
if error.message <> "" then
message(error.message)
else
message("Invoice printed succesfully for order no %d", sales.order.no)
endif
else
message("error.message")

endif
stpapi.end.session("tdsls4404m000")
}

mark_h
11th November 2005, 16:17
Do not use this session, but continue would be the correct choice. i would check each of the fields you are doing a put on - here is what I would change:

stpapi.put.field("tdsls4404m000", "inv.date", str$(date.num()))
stpapi.put.field("tdsls4404m000", "definite", str$(tcyesno.yes))
stpapi.put.field("tdsls4404m000", "direct.process", str$(tcyesno.yes))
stpapi.put.field("tdsls4404m000", "totals", str$(tcyesno.yes))
stpapi.put.field("tdsls4404m000", "prnt.options", str$(tcyesno.yes))
stpapi.put.field("tdsls4404m000", "prnt.sellpr", str$(tcyesno.yes))

Just make sure that you use the correct yes/no domain. It looks like it actually works, just need to make sure the correct data in the correct format is being put to the form.

vineetu1
13th November 2005, 12:32
I debuged the session tdsls4404m000 aloing with the AFS script. I find that the form field values passed through AFS are not getting reflected in tdsls4404m000. e.g. when order no is being passesd as 840121 the orno.f and orno.t field has the old default value 770134.

What coult be the issue.

mark_h
14th November 2005, 03:17
Did you make the above changes? Then try debugging. I do not think you can just pass "No" to a yes/no field. Try this and if that does not work try deleting the user defaults. I usually do not do this, but I have had user defaults cause me problems.

vineetu1
3rd December 2005, 10:44
I have tried all the possible options and have not been successful.

Through debugging I find that the values passed to the form through stpapi.put.field() are not reflected on the session.

Would like to know whether any body has been successful in automating the session through AFS ??

csecgn
3rd December 2005, 12:13
I've never tried this session but, if you want to pass an enum, use i.e. str$(etol(tcyesno.yes)).

Regards
csecgn

mark_h
5th December 2005, 17:19
This thread (http://www.baanboard.com/baanboard/showthread.php?t=9636&highlight=tdsls4404m000) indicates others as being successful. One even makes note about what csecgn recommends. There is also a solution recommended.

vineetu1
15th December 2005, 15:56
Thanks everybody,


with a combination of str$(etol(tcyesno.yes)), stpapi.clear() and removing the users session defaults I have been able to execute the session with AFS.

I would also like to mention that we can use the display device while setting the report. (I read in some post that display device cannot be used)

mark_h
15th December 2005, 16:17
I do not remember that post, but the display device is valid. I just usually prevent my users from selecting it in certain sessions(it can be ugly when they decide to print 200 purchase orders to the screen).

Also remember that somewhere along the way the user might save defaults again. Usually you can override defaults by putting all the fields - even then I have had problems. One of the first things I do is delete user defaults for all sessions being used. And the worst session for saving defaults is ttstpsplopen - over a period of time this appears to corrupt reports being printed.