Monday, October 17, 2016

Saving PO report as PDF in the shared path

/// <summary>
/// This method generates the PO Confirmation report.
/// </summary>
/// <param name="_purchTable">
/// Gets the PurchTable buffer.
/// </param>
/// <remarks>
/// Generates the PO Confirmation report.
/// </remarks>

//Begin
private void AVAPOConfrimationReportGeneration(PurchTable _purchTable)
{
    SrsReportRunController          ssrsController = new SrsReportRunController();
    PurchPurchaseOrderContract      Contract = new PurchPurchaseOrderContract();
    SRSPrintDestinationSettings     printerSettings;
    VendPurchOrderJour              VendPurchOrderJrn;
    str                             poReportPath;
    ;

    select firstOnly RecId from VendPurchOrderJrn
    order by VendPurchOrderJrn.createdDateTime DESC
    where VendPurchOrderJrn.PurchId == _purchTable.PurchId;

    poReportPath = PurchParameters::find().AvaPurchOrderPath + '\\'  + _purchTable.PurchId +'.pdf';
    ssrsController.parmReportName(ssrsReportStr(PurchPurchaseOrder, Report));
    ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    ssrsController.parmShowDialog(false);
    Contract.parmRecordId(VendPurchOrderJrn.RecId);
    ssrsController.parmReportContract().parmRdpContract(Contract);

    //link the printer settings to the controller
    printerSettings = ssrsController.parmReportContract().parmPrintSettings();
    //print to pdf and always overwrite if the file exists
    printerSettings.printMediumType(SRSPrintMediumType::File);
    printerSettings.fileFormat(SRSReportFileFormat::PDF);
    printerSettings.overwriteFile(true);
    printerSettings.fileName(@poReportPath);

    try
    {
    //run & save the report
    ssrsController.runReport();
    }
    catch(Exception::CLRError)
    {
        //Access the last CLR Exception
        info(CLRInterop::getLastException().ToString());
        AifUtil::getClrErrorMessage();
        //See AifUtil::getClrErrorMessage for another alternative
        //how to parse the Exception object
    }
}
//End

No comments:

Post a Comment