How to: Overwrite Print Management on a SSRS report on Dynamics AX 2012

Today we are going to show you how to overwrite the print management settings on a SSRS report, this can be useful if you make a custom design on a standard report.

First, the print management can be found on almost all the modules of Dynamics AX. For this example we are going to use the “Accounts Payable” module, we can find the print management form for this module on the following route: DAT/Accounts receivable/Area page/Set Up/Form Set Up:

Captura de pantalla de 2015-03-06 16:10:26

Here we need to click on “Print management” and this will open the following form:

Captura de pantalla de 2015-03-06 16:11:21

For this example we are going to use the Customer Account Statement report. We saw on the previous image that this has a design configured named CustAccountStatementExt.report. So we created already a custom design for this report and we named it CustAccountStatementExtAux, to use it we are going to edit the class “CustAccountStatementExtController” on the method runPrintMgmt(lines 116 to 121):

 X++ |  copy code |? 
001
002
/// <summary>
003
///    Runs the print report.
004
/// </summary>
005
protected void runPrintMgmt()
006
{
007
    CustTable partyCust;
008
    container selectedCompanyList;
009
    QueryRun partyQueryRun;
010
    SrsReportPreRunState preRunValidateState;
011
    CustStatementDirTmp custStatementDirTmp;
012
 
013
    // Pre-validate the number of reports that will be printed
014
    initialPreRunValidate = true;
015
    preRunValidateState = this.processPreRunValidate();
016
    initialPreRunValidate = false;
017
    if (preRunValidateState != SrsReportPreRunState::Run)
018
    {
019
        return;
020
    }
021
 
022
    // Report Parameters
023
    statementStartDate = this.parmContract().parmFromDate();
024
    statementEndDate = this.parmContract().parmToDate() == dateNull() ? maxDate() : this.parmContract().parmToDate();
025
    onlyOpen = this.parmContract().parmOnlyOpen();
026
    includeReversed = this.parmContract().parmIncludeReversed();
027
    printGiro =  this.parmContract().parmPrintGiro();
028
    printNotZero = this.parmContract().parmPrintNonZero();
029
    printAmountOnGiro = this.parmContract().parmPrintAmountGiro();
030
    printPaymentSchedule = this.parmContract().parmPrintPaymentSchedule();
031
    specifyDueToDate = this.parmContract().parmSpecifyDueToDate();
032
    query = this.getFirstQuery();
033
 
034
    showAging = this.parmContract().parmPrintAging(); // Controls whether any aging is shown
035
    if(showAging)
036
    {
037
        useAgingDefinition = this.parmContract().parmAgingPeriod(); // predefined or manually defined aging periods?
038
        if(useAgingDefinition)
039
        {
040
            agingDefinition = this.parmContract().parmAgingBucket(); // If using predefined aging, this is the aging definition name
041
            showAgingDescription = this.parmContract().parmAgingBucketPrintDescription() == NoYesCombo::Yes;
042
        }
043
        else
044
        {
045
            manualAgingInterval = this.parmContract().parmInterval();
046
            manualAgingDayMonth = this.parmContract().parmDayMonth();
047
            manualAgingDirection = this.parmContract().parmPrintingDirection();
048
        }
049
    }
050
 
051
    statementCompany = curext();
052
 
053
    if(this.getGiroType() != PaymentStub::None)
054
    {
055
        SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(CustTable)), fieldNum(CustTable, GiroTypeAccountStatement)).value(strFmt('%1', this.getGiroType()));
056
    }
057
 
058
    formLetterReport.parmDefaultCopyPrintJobSettings(this.getReportContract().parmPrintSettings());
059
    formLetterReport.parmDefaultOriginalPrintJobSettings(this.getReportContract().parmPrintSettings());
060
 
061
    formLetterReport.parmUsePrintMgmtDestinations(this.parmContract().parmUsePrintManagement());
062
 
063
    // Company list
064
    selectedCompanyList = CustAccountStatementExtController::getSelectedCompanyList(query, curext());
065
 
066
 
067
    if(this.getGiroType() == PaymentStub::FIK752 && (Ledger::accountingCurrency(CompanyInfo::find().RecId) != 'DKK' || this.checkCurrency()))
068
    {
069
        info("@SYS343346");
070
    }
071
 
072
    if (this.getGiroType() == PaymentStub::ESR_red_bank && this.checkMultipleCurrency())
073
    {
074
        throw info("@SYS344476");
075
    }
076
 
077
    this.setCommonData();
078
 
079
    // Checking start date and end date
080
    if (statementStartDate == dateNull() || statementEndDate == dateMax())
081
    {
082
        showAging = false;
083
    }
084
 
085
    if(conLen(selectedCompanyList) != 0)
086
    {
087
 
088
        // Building query
089
        partyQueryRun = new QueryRun(CustAccountStatementExtController::createPartyQuery(query));
090
        CustAccountStatementExtController::buildPartyList(query.pack(), selectedCompanyList, custStatementDirTmp);
091
        partyQueryRun.setCursor(custStatementDirTmp);
092
        while(partyQueryRun.next())
093
        {
094
            partyCust = partyQueryRun.get(tableNum(CustTable));
095
 
096
            createdTransactionId = 0;
097
 
098
            // Reset this flag after printing each customer details.
099
            custAccountStatementExtTmp.Flag = 0;
100
 
101
            // If no customer language is specified use current user language
102
            languageId = partyCust.languageId() ? partyCust.languageId() : infolog.language();
103
 
104
            ttsbegin;
105
            this.processParty(query, partyCust.Party, selectedCompanyList);
106
            ttscommit;
107
 
108
            // only run the report if any data was inserted
109
            if(createdTransactionId)
110
            {
111
                this.parmContract().parmRecordId(createdTransactionId);
112
                this.parmContract().parmCustAccount(partyCust.AccountNum);
113
 
114
                this.parmReportContract().parmRdlContract().parmLanguageId(languageId);
115
                formLetterReport.loadPrintSettings(partyCust, partyCust, languageId, partyCust.AccountNum);
116
                //Modification start
117
                if(mycondition)
118
                {
119
                    this.PrintJobSettings(formLetterReport);
120
                }
121
                //Modification end
122
                this.outputReports();
123
            }
124
        }
125
    }
126
}
127

Now this will call the new method that we are going to create using the following code:

 X++ |  copy code |? 
01
02
private void PrintJobSettings(FormLetterReport  _formLetterReport)
03
{
04
    boolean                     useUserDefinedDestinations;
05
    PrintMgmtPrintSettingDetail printSettingDetail = new PrintMgmtPrintSettingDetail();
06
    PrintMgmtReportFormat       printMgmtReportFormat;
07
 
08
    //In the below statement , i pass the custom format/design, to be picked     You can also use switch statement to pass different formats, if you have 2 or more custom formats/designs.
09
    printSettingDetail.parmReportFormatName(PrintMgmtDocType::construct(PrintMgmtDocumentType::CustAccountStatementAux).getDefaultReportFormat()); //This is the important line
10
 
11
    printSettingDetail.parmType(PrintMgmtDocInstanceType::Original);
12
    printSettingDetail.parmInstanceName(enum2str(PrintMgmtDocInstanceType::Original));
13
    // Since this will be reported to the screen, one copy is the only thing that makes sense
14
    printSettingDetail.parmNumberOfCopies(1);
15
    printSettingDetail.parmPrintJobSettings(_formLetterReport.parmReportRun().parmDefaultOriginalPrintJobSettings());
16
    if (!_formLetterReport.parmUseUserDefinedDestinations())
17
    {
18
    printSettingDetail.parmPrintJobSettings().printMediumType(SRSPrintMediumType::Screen);
19
    }
20
    _formLetterReport.parmReportRun().loadSettingDetail(printSettingDetail,"");
21
}
22

So this piece of code will read the formletterreport class and with the PrintMgmtPrintSettingDetail class will create a new set of parameters where we are going to set the new design as we can see on line 7.With this new set of parameter we are going to fill the formLetterrReport class, and that’s it!

We have shown you how to set a custom design on a ssrs report that uses Print management, hope you like it and see you next time.

  • Itsuki Minami

    by LP