Thursday, November 27, 2014

Multiple report design association in Dynamics AX 2012 SSRS using X++

It is obvious that we customize many document reports e.g. Sales order, Purchase order, Quotation, Projects for a new report design and call the report from different journal accordingly. There are few ways to specify the new report design, using Print management document or setting this new report design as a system report in the table "PrintMgmtReportFormat".

In most of the cases, AX SSRS report controller class call for the system report from PrintMgmtReportFormat table using the following method:


PrintMgmtReportFormat::findSystem(this.getPrintMgmtDocumentType()).Name);


The controller class has a method  "runPrintMgmt" which is responsible for defaulting the system report. In this method, the class object FormLetterReport does the actual job for calling and assigning system report with printer setting.

formLetterReport.loadPrintSettings(custQuotationJour, custQuotationJour.salesQuotationTable(), this.quoteLanguageId());

So here my code goes. I write a method and call this after the above line of code in the controller class. This custom method basically initializes the PrintMgmtPrintSettingDetail object and conditionally, I am passing my custom report design. In this way, it overrides the print setting with my new report design.

void customPrintSettings()
{
    PrintMgmtDocInstanceType        type;
    PrintMgmtPrintSettingDetail     printSettingDetail      = new    
    PrintMgmtPrintSettingDetail();
    SRSPrintDestinationSettings     defaultSettings         = 
    formLetterReport.parmReportRun().parmDefaultOriginalPrintJobSettings();
    PrintMgmtReportFormatName       reportFormatName        = 
    ssrsReportStr(PSAQuotations, CustomReportSG); //Passing custom report design

    if (formLetterReport.parmPrintType() == PrintCopyOriginal::Original)

    {
        type =  PrintMgmtDocInstanceType::Original;
    }

    if (formLetterReport.parmPrintType() == PrintCopyOriginal::Copy)

    {
        type =  PrintMgmtDocInstanceType::Copy;
    }

    printSettingDetail.parmReportFormatName(reportFormatName);


    printSettingDetail.parmType(type);


    printSettingDetail.parmInstanceName(enum2str(type));


    // Since this will be reported to the screen, one copy is the only thing that makes sense

    printSettingDetail.parmNumberOfCopies(1);

    printSettingDetail.parmPrintJobSettings(defaultSettings);


    if (!formLetterReport.parmUseUserDefinedDestinations())

    {
        printSettingDetail.parmPrintJobSettings().printMediumType(
        SRSPrintMediumType::Screen);
    }

    formLetterReport.parmReportRun().loadSettingDetail(printSettingDetail);

}

Cheers !!!

2 comments:

  1. thank for the post but I didn't get it well.. where did you put this code or what controller?

    ReplyDelete