web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to send salesInvoice report directly to a printer if a flag is true?

(1) ShareShare
ReportReport
Posted on by 214
Hi seniors,

I have a requirement of sending salesInvoice report directly to a network managed printer if a custom flag is yes. I do not want to do it using print management as print management is already being used for email. 

I have done code in the controller class of salesInvoice report. Below is my code.  
Note: OutputType is a custom toggle field.
[ExtensionOf(classStr(SalesInvoiceController))]
internal final class SalesInvoiceController_Class_Extension
{
    static void PrintSalesInvoiceReportToPrinter(Args _args)
    {
        SRSPrintDestinationSettings     settings;
        SalesTable                      salesTable;
        SysCorpNetPrinters              sysCoprNetPrinters;
        CustInvoiceJour                 custInvoiceJour;

        SrsReportRunController          controller = new SrsReportRunController();
        SalesInvoiceContract            salesInvoiceContract = new SalesInvoiceContract();;
        
 
        controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
        controller.parmShowDialog(false);
        controller.parmArgs(_args);
        
        custInvoiceJour = _args.record();

        select firstonly OutputType from salesTable
            where salesTable.SalesId == custInvoiceJour.SalesId;

        select firstonly PrinterName, PrinterPath from sysCoprNetPrinters
            where sysCoprNetPrinters.Active == NoYesCombo::Yes;

        if(salesTable.OutputType == "PDF" && sysCoprNetPrinters.PrinterName)
        {
            // Change print settings as needed
            settings = controller.parmReportContract().parmPrintSettings();
            settings.printMediumType(SRSPrintMediumType::Printer);
            settings.printerName(sysCoprNetPrinters.printerName);
            settings.printerWhere(sysCoprNetPrinters.PrinterPath);
            settings.numberOfCopies(1);
            settings.printAllPages(true);
            
            salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
            controller.parmReportContract().parmRdpContract(salesInvoiceContract);

            // Execute the report
            controller.startOperation();
        }
    }

    public static void main(Args _args)
    {

        if(_args.record())
        {
            SalesInvoiceController::PrintSalesInvoiceReportToPrinter(_args);
        }

        next main(_args);
    }
}

My code is running fine and I have also configured Document routing agent. But the issue is that the report is printing only one page but when on screen the report is of 2 pages. Also, I have noticed some difference between when I print using code (prints 1 page and some text missing on paper) and when I manually print the report (print 2 pages and exact same texts on paper) using the print option on a browser. I have already tried the following things but no luck.
 
srsPrintDestinationSettings.collate(false);
srsPrintDestinationSettings.printOnBothSides(SRSReportDuplexPrintingSetting::None);
srsPrintDestinationSettings.printAllPages(true);
srsPrintDestinationSettings.fromPage(0);
srsPrintDestinationSettings.toPage(0);

Can anyone suggest if I am doing the code in correct place/method/class. Do I need to do something more as well?

Regards,
Arif Hussain
  • Arif Hussain Profile Picture
    214 on at
    @ André Arnaud de Cal /Martin Dráb / anyone please help. 
  • Martin Dráb Profile Picture
    241,509 Most Valuable Professional on at
    Isn't print management all you need? It supports both multiple print destinations and conditions.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 320 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 210

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans