6 Ocak 2014 Pazartesi

AX 2012 - Create SSRS report PDF output

I got help from Martin Drab's blog for create PDF with AX 2012:

void CreatePDF(Str60 _Subject,Notes _Body)
{
MYReportPurchController          controller;
MYReportPurchContract            rdpContract = new MyReportPurchContract();
SRSPrintDestinationSettings settings;
Args                        args = new args();
str                         fileName;

args.record(this);
controller = MYReportPurchController::construct(args);
// Define report and report design to use
controller.parmReportName(ssrsReportStr(EtgPurchOrderForm,PrecisionDesign1));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
// Suppress report dialog

// Explicitly provide all required parameters
controller.parmReportContract().parmRdpContract(rdpContract);
    //rdpContract.
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.overwriteFile(true);
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
//settings.

    #WinAPI

  fileName = WinApi::getTempPath() +this.PurchOrderDocNum+".PDF";
settings.fileName(fileName);
// Execute the report
    controller.parmShowDialog(false);
    controller.startOperation();
}


Or send selected records to PDF by RDP report:
 
SMAServiceOrderTable        serviceOrder;
    MultiSelectionHelper        helper;
    FormRun                     caller = _args.caller();
    FormDataSource              SMAServiceOrderTable_DS;
    SRSPrintDestinationSettings settings;
    ETGServiceReportContract    contract = new ETGServiceReportContract();
    SrsReportRunController      controller;
    Filename                    fileName;
    int                         counter;
    SysMailer                   mailer = new SysMailer();
    SysEmailParameters          parameters = SysEmailParameters::find();
    Dialog                      dialog;
    DialogField                 field;
    Email                       email;

    dialog = new Dialog("Servis Raporu Gönderme");
    field = dialog.addField(ExtendedTypeStr(email));
    dialog.run();

    if (!dialog.closedOK())
        return;
    email = field.value();
    if (email == "")
        throw error("Bir mail adresi girmelisiniz!..");

    SMAServiceOrderTable_DS = caller.dataSource();
    helper = MultiSelectionHelper::createFromCaller(caller);
    if (parameters.SMTPRelayServerName)
    {
        mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
                            parameters.SMTPPortNumber,
                            parameters.SMTPUserName,
                            SysEmailParameters::password(),
                            parameters.NTLM);
    }
    else
    {
        mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
                            parameters.SMTPPortNumber,
                            parameters.SMTPUserName,
                            SysEmailParameters::password(),
                            parameters.NTLM);
    }
    
    mailer.fromAddress('noreply@sinbo.com.tr');
    mailer.tos().appendAddress(email);
    mailer.htmlBody('<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">Sayın Yetkili,<br><br> Servis raporu kopyanız ektedir.<br><br>Saygılarımızla,<br><br><br>Sinbo');
    mailer.subject('Sinbo Servis Raporu');
    mailer.bodyCharSet("Windows-1254");

    helper.createQueryRanges(SMAServiceOrderTable_DS.queryBuildDataSource(),fieldStr(SMAServiceOrderTable,RecId));
    serviceOrder = helper.getFirst();

    while(serviceOrder)
    {
        controller = new SrsReportRunController();
        controller.parmReportName(ssrsReportStr(ETGServiceReport, Report));
        contract = controller.parmReportContract().parmRdpContract();
        controller.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Screen);
        controller.parmShowDialog(false);
        contract.parmServiceOrderId(serviceOrder.ServiceOrderId);

        counter++;
        fileName = WinApi::getTempPath() + strFmt("Servis Raporu %1.PDF",counter);
        
        settings = controller.parmReportContract().parmPrintSettings();
        settings.overwriteFile(true);
        settings.printMediumType(SRSPrintMediumType::File);
        settings.fileFormat(SRSReportFileFormat::PDF);
        settings.fileName(fileName);
        
        controller.startOperation();
        mailer.attachments().add(fileName);
        serviceOrder = helper.getNext();
    }
    if (counter == 0)
        return;
    infolog.clear();



    mailer.sendMail();

Hiç yorum yok:

Yorum Gönder