Printing directly to a certain printer based on logic

Namnack
Member Posts: 15
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;
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
-
BlackTiger wrote:Change your coding style first... It's awful.
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!Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Yes, but afaik the printer selection solution is only possible if the user didn't change the page setup for this certain report. The setup will be stored in the .zup file and will be taken even if there is a record in table print selction."Money is likewise the greatest chance and the greatest scourge of mankind."0
-
There is another problem.
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.Keep It Simple and Stupid (KISS), but never oversimplify.0 -
Thx, for sharing the code.
Could someone move this to tricks and tips.
0 -
I would have to protest against this being moved to Tips & Tricks.
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)0 -
Xypher wrote:I would have to protest against this being moved to Tips & Tricks.
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)Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
It's a good trick and everytime someone shares code this forum gets better and better. Off course it can be coded in a different way but i've seen snippets of code in this forum done worse.
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.0 -
kriki wrote:1. Was your code perfect and beautiful from the beginning?BlackTiger wrote:1. I know, it's hard to believe... Yes, on the second week.
Regards,
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
BlackTiger wrote:(ok... let's zi battle begins)
1. I know, it's hard to believe... Yes, on the second week.
2. I believe... Just look at standard code and read coding recomendation. It's enougn.
Here is mine:
1) So, no any "notations" whatsoever. Neither "camel", nor "hungarian". Any notation is stupid in modern coding.
2) Spaces before and after ":=".
3) Full readable names for fields and tables. "Short readable" names for variables.
4) NO spaces in list of parameters for procedure/method.
5) BEGIN on same line as "THEN"
6) Enclose REPEAT..UNTIL in BEGIN..END in constructions like "IF..THEN..BEGIN REPEAT..UNTIL..; END;
7) NO (bloody) BLOCK COMMENTS! ("{...}")
8) Use IF (NOT) Table.ISEMPTY THEN Table.DELETEALL; instead of IF Table.FIND(NEXT,LAST) THEN Table.DELETEALL;
Ok. 8 points enough.
PS:
9) (personal) Use "MethodName();" if method has no parameters.
10) Do not put tablename in "Table.SETRANGE(<tablename>.Field,Value1,Value2);"
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...NAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
DataItemTableView (which I think you were referring to near the end of your post) is still nice to use. That is if you don't want the ReqFilter to show a tab for that dataitem.
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 BlackTiger0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions