Hi,
I read a couple of unresolved issues regarding the above topic.
It is actually possible to directly print to a certain printer depending on values in e.g. the customer record.
What you can do for example is use the REPORT.MODAL function which checks for a record in the printer selection table based on USERID and reportnumber. In order to print to a designated printer, just temporarily write a new record into the printer selections table, specifying the combination of userid, printername and reportnumber, just before executing the RUNMODAL command. Afterwards the record can be deleted again within the same code.
In order for this to work of course, the record inserted into the printer selection table needs to be unique.
E.g. :
IF RecCustomer.GET(SalesHeader."Sell-to Customer No.") THEN BEGIN
IF RecCustomer.Boolean THEN BEGIN
recPrinterselection.INIT;
recPrinterselection."User ID":=USERID;
recPrinterselection."Report ID":=205;
recPrinterselection."Printer Name":='Printername,CPW2:';
recPrinterselection.INSERT;
REPORT.RUNMODAL(205,FALSE,FALSE,SalesHeader."No.");
recPrinterselection.SETRANGE(recPrinterselection."User ID",USERID);
recPrinterselection.SETRANGE(recPrinterselection."report ID",205); IF recPrinterselection.FIND('-') THEN
recPrinterselection.DELETEALL;
0
Comments
1. Was your code perfect and beautiful from the beginning?
2. If your code is perfect and beautiful now, why don't you start teaching him HOW to write it!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
You need to do a COMMIT before you can use the RUNMODAL.
So the INSERT will be definitive.
--> If there's an error in the report, then the original situation will not be restored.
--> If there is another session with the same USERID, then this will give problems.
Being that most would insist on not hard coding something like this. (Which could cause more problems in the future than it would currently provide useful)
(Including fverkel's mentioned problems as well as others)
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
The idea is good and with the remarks from the replies, I (and others) can make my own decision how or not to implement it. :-# Thx again Namnack and keep on sharing.
Regards,
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
I sort of agree with blacktiger except points 1, 4, 6
I prefer not to use BEGIN END if the situation does not call for it, also keep to the same line if situation permits so less scrolling up & down searching for codes (IF ... THEN DO IT).
For 3, I'' like to add not to create variables unless absolutely necessary,
also please don't do funny things like having a function to just return TRUE/FALSE & this function is hidden in some obscure codeunit somewhere & variable was created just for this...
For 8. please help to change all occurrence of standard codings FIND('-') to FIND (NEXT, LAST) so I have less tuning to do, etc..., while we'are at it please also change all instances of similar i := i + 1 into i += 1...
I also prefer linking tables to be specified in OnPreDataItem() rather than DataItemLink, I don't use DataItemLink or DataItemView anymore...
ERP Consultant (not just Navision) & Navision challenger
But yeah this is turning into another topic. Since the debate on code formatting is purely based on opinion (the computer doesn't care how you type it as long as it can make sense of it) you might as well take the conversation to private messages with BlackTiger