Dynamics AX Blog - report

These posts are machine-translated.
Currently, only posts are displayed, which contain the tag »report« Filter entfernen

Debugging SSRS-Dataprovider which extends SrsReportDataProviderPreProce

In Debugging SSRS-Dataprovider I have already described how to "debug" a DataProvider derived from SRSReportDataProviderBase.

The following job basically does the same, but for preprocessed reports, where the DataProvider is derived from SrsReportDataProviderPreProcess. In the example, I use the DataProvider of an invoice (SalesInvoice).

static void testSSRSDataProvider_SalesInvoice(Args _args)
{
    SalesInvoiceTmp salesInvoiceTmp;
    SalesInvoiceDP dataProvider = new SalesInvoiceDP();
    SalesInvoiceContract contract;
    CustInvoiceJour CustInvoiceJour = CustInvoiceJour::findRecId(35637191172);
    UserConnection UserConnection;

    try
    {
        ttsBegin;

        UserConnection = new UserConnection();

        contract = new SalesInvoiceContract();
        contract.parmFormLetterRecordId(CustInvoiceJour.RecId);
        contract.parmRecordId(CustInvoiceJour.RecId);

        dataProvider = new SalesInvoiceDP();
        dataProvider.parmDataContract(contract);
        dataProvider.parmUserConnection(UserConnection);
        dataProvider.processReport();

        salesInvoiceTmp = dataProvider.getSalesInvoiceTmp();
        
        while select salesInvoiceTmp
            where SalesInvoiceTmp.createdTransactionId == appl.curTransactionId()
        {
            info(strFmt("%1 %2", SalesInvoiceTmp.InvoiceId, SalesInvoiceTmp.ItemId));
        }

        ttsCommit;
    }
    catch (Exception::Break)
    {
        info("Aborted");
    }
}

 


 
 
 

Get design names of a SSRS report

Anyone who has the need to get the available designs of a SSRS report, can use the following job.

static void listDesignsOfSSRSReport(Args _args)
{
    TreeNode treeNode;
    TreeNode treeNodeDesign;
    #aot
  
    treeNode = TreeNode::findNode(#SSRSReportsPath + #AOTRootPath);
    treeNode = treeNode.AOTfindChild("SalesPackingSlip");
    treeNodeDesign = treeNode.AOTfindChild("Designs");
  
    treeNodeDesign =
    treeNodeDesign.AOTfirstChild();
    while(treeNodeDesign)
    {
        info(treeNodeDesign.AOTname());   
      
        treeNodeDesign = treeNodeDesign.AOTnextSibling();
    }
}

 
 
 

Debugging SSRS-Dataprovider

In the past i often had the problem, that i had to debug a dataprovider of a SSRS-Report, which could not be debugged using the well known Dynamics AX Debugger (for example because the dataprovider is executed only on server).

Therefore i created the below job (DataProvider has to extend SRSReportDataProviderBase), which only puts the content of the created (temporary) table to an simple infolog.

In the example the report "Work note" of the service module is used.

static void testSSRSDatProvider(Args _args)
{
    SMAWorkNoteTmp      tempTable;
    SMAWorkNoteDP       dataProvider = new SMAWorkNoteDP();
    SMAWorkNoteContract contract = new SMAWorkNoteContract();
    Query               query = new Query(identifierStr(SMAWorkNote));

    try
    {
        SysQuery::findOrCreateRange(
            query.dataSourceTable(
                tableNum(SMAServiceOrderTable)),
                fieldNum(SMAServiceOrderTable, ServiceOrderId)).value("00018");

        contract.parmItemConsumption(true);
        contract.parmItemRequirement(true);
        contract.parmExpense(true);
        contract.parmFee(true);
        contract.parmAdditionalNotes(true);
        contract.parmLineText(true);

        if( !contract.validate())
        {
            throw error(error::missingParameter(contract));    
        }

        dataProvider.parmDataContract(contract);
        dataProvider.parmQuery(query);
        dataProvider.processReport();

        tempTable = dataProvider.getSMAWorkNoteTmp();

        while select tempTable
        {
            info(tempTable.otServiceOrderId);
        }
    }
    catch (Exception::Break)
    {
        info("Aborted");
    }
}

 
 
 

Print packing slip through code

The following job demonstrates, how you can print an existing Sales packing slip through code. The example sends the report to screen.

static void printSalesPackingSlipThroughCode(Args _args)
{
    SalesPackingSlipJournalPrint salesPackingSlipJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(CustPackingSlipJour::findRecId(5637161120));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen);

    // Initalize
    salesPackingSlipJournalPrint = SalesPackingSlipJournalPrint::construct();
    salesPackingSlipJournalPrint.parmPrintFormletter(NoYes::Yes);
    salesPackingSlipJournalPrint.parmUsePrintManagement(false);
    salesPackingSlipJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    salesPackingSlipJournalPrint.printJournal(set);
}

Changing the parameter of the instance of SRSPrintDestinationSettings allows you to send the sales packing slip to printer, file or mail. The next example creates a PDF-file.

static void printSalesPackingSlipThroughCode(Args _args)
{
    SalesPackingSlipJournalPrint salesPackingSlipJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(CustPackingSlipJour::findRecId(5637161120));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF);
    srsPrintDestinationSettings.fileName(@'c:	emppackingslip.pdf');
    srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::File);
    srsPrintDestinationSettings.numberOfCopies(1);
    srsPrintDestinationSettings.overwriteFile(true);

    // Initalize
    salesPackingSlipJournalPrint = SalesPackingSlipJournalPrint::construct();
    salesPackingSlipJournalPrint.parmPrintFormletter(NoYes::Yes);
    salesPackingSlipJournalPrint.parmUsePrintManagement(false);
    salesPackingSlipJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    salesPackingSlipJournalPrint.printJournal(set);
}

If you want to print multiple sales confirmations at once, you have to add the corresponding CustPackingSlipJour-records to the set called "set:

    ...    
    // Add record
    set.add(CustPackingSlipJour::findRecId(5637155842));
    set.add(CustPackingSlipJour::findRecId(5637145354));
    ...

To additionally save the sales packing slip to print archive, you can add the following line:

    ...    
    srsPrintDestinationSettings.parmPrintToArchive(true);
    ...

 
 
 

Print sales invoice through code

The following job demonstrates, how you can print an existing Sales invoice through code. The example sends the report to screen.

static void printSalesInvoiceThroughCode(Args _args)
{
    SalesInvoiceJournalPrint salesInvoiceJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(CustInvoiceJour::findRecId(5637188088));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen);

    // Initalize
    salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct();
    salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes);
    salesInvoiceJournalPrint.parmUsePrintManagement(false);
    salesInvoiceJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    salesInvoiceJournalPrint.printJournal(set);
}

 
 
 

AX 2012: Print document through code

With the following job you can reprint an order confirmation by code and have it output as a PDF file.

With the help of similarly named classes such as the SalesConfirmJournalPrint used here, it should also be possible to reprint other documents such as invoices or delivery notes.

static void printSalesConfirmThroughCode(Args _args)
{
    SalesConfirmJournalPrint SalesConfirmJournalPrint;
    set set = new set(Types::Record);
    SRSPrintDestinationSettings SRSPrintDestinationSettings;
    
    // Add record
    set.add(CustConfirmJour::findRecId(5637150827));
    
    // Set printer settings
    SRSPrintDestinationSettings = new SRSPrintDestinationSettings();
    SRSPrintDestinationSettings.fileFormat(
        SRSReportFileFormat::PDF);
    SRSPrintDestinationSettings.fileName(@'c:ab.pdf');    
    SRSPrintDestinationSettings.printMediumType(
        SRSPrintMediumType::File);
    SRSPrintDestinationSettings.numberOfCopies(1);
    SRSPrintDestinationSettings.overwriteFile(true);
    
    // Initalize 
    SalesConfirmJournalPrint = SalesConfirmJournalPrint::construct();
    SalesConfirmJournalPrint.parmPrintFormletter(NoYes::Yes);
    SalesConfirmJournalPrint.parmUsePrintManagement(false);
    SalesConfirmJournalPrint.parmPrinterSettingsFormLetter(
        SRSPrintDestinationSettings.pack());
    
    // Print
    SalesConfirmJournalPrint.printJournal(set); 
}

 
 
 

 

 
 
 
Posts of the actual month
Juli 2019
MoTuWeThFrSaSu
1234567
891011121314
15161718192021
22232425262728
293031 
 
© 2006-2019 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.