Fork me on GitHub

Print SSRS Report directly to the printer [AX2012]

Printing class

A simple class to print SSRS report directly to the printer.

/// <summary>
/// Print SSRS report directly
/// </summary>
[SysEntryPointAttribute(true)]
public void printReport(SRSCatalogItemName reportName,
                        SRSPrintMediumType printMediumType,
                        Name printerName,
                        TableId tableId,
                        FieldId fieldId,
                        str 254 rangeValue)
{
    SrsReportRunController  controller;
    SrsReportDataContract   contract;
    Map                     queryContracts;
    MapEnumerator           mapEnum;
    QueryBuildRange         range;

    // Create the report run controller
    controller = new SrsReportRunController();
    controller.parmReportName(reportName);
    controller.parmShowDialog(false);
    controller.parmLoadFromSysLastValue(false);

    contract  = controller.parmReportContract();
    queryContracts = contract.parmQueryContracts();
    mapEnum = queryContracts.getEnumerator();

    while(mapEnum.moveNext())
    {
        // Get the query and update the datasource as required
        query = mapEnum.currentValue();
        range = SysQuery::findOrCreateRange(query.dataSourceTable(tableId), fieldId);
        range.value(rangeValue);
    }

    // Set printer settings (you can print to file, format, filename, etc).
    controller.parmReportContract().parmPrintSettings().printMediumType(printMediumType);
    controller.parmReportContract().parmPrintSettings().printerName(@printerName);

    //set the execution mode to Synchronous
    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

    // Run the report
    controller.run();
}

Usage

YourService yourService = new YourService();

yourService.printReport(ssrsReportStr(ProdRouteCard, Report),
                        SRSPrintMediumType::Printer,
                        @"\\printers\YourPrinterName",
                        tableNum(ProdTable),
                        fieldNum(ProdTable,ProdId),
                        "PROD123");

Comments !

links

social