Running the SSRS Report and Saving in Local drive using X++ Code with renaming the same report next Occurrence in AX 2012

Running the SSRS Report and Saving in Local drive using X++ Code with renaming the same report next Occurrence in AX 2012

Write the below code in Controller Class  of the Report

public static void main(Args _args)
{
    //KKSalesPackingSlipController controller = new KKSalesPackingSlipController();
    //controller.parmReportName(ssrsReportStr(KKSalesPackingSlipReport, PrecisionDesign2));
    ////controller.parmReportName(ssrsReportStr(KK_CustInvReport, Report));
    //controller.parmArgs(_args);
    //controller.startOperation();


    LogisticsAddressCountryRegionId     logisticsAddressCountryRegionId;
    SrsReportRunController              controller = new SrsReportRunController();
    SRSPrintDestinationSettings         printSettings;
    KKSalesPackingSlipContract          contract = new KKSalesPackingSlipContract();
    Str                                 filePath,filePath1;
    int                                 i = 0;

    // set report name
    controller.parmReportName(ssrsReportStr(KKSalesPackingSlipReport, Report));

    //getting contract parameter to set filename
    contract                        = controller.parmReportContract().parmRdpContract();
    logisticsAddressCountryRegionId = contract.parmCountryRegionId();
   
    //setting file path
    filePath                        = strFmt("C:\\temp\\%1.pdf",logisticsAddressCountryRegionId);

    // get print settings from contract
    printSettings = controller.parmReportContract().parmPrintSettings();

    // set print medium
    printSettings.printMediumType(SRSPrintMediumType::File);
    printSettings.fileFormat(SRSReportFileFormat::PDF);
    printSettings.overwriteFile(false);

    while(WinAPI::fileExists(filePath))
    {
        i++;
        filePath = strFmt("C:\\Temp\\%1_%2.pdf",logisticsAddressCountryRegionId,i);

    }
   
    //printSettings.fileName(@"C:\temp\"+logisticsAddressCountryRegionId+".pdf");
    printSettings.fileName(@filePath);

    //suppress the parameter dialog
    controller.parmShowDialog(true);
   
    //start operation
    controller.startOperation();
}

Comments

Popular posts from this blog

How to Calculate Planned Purchase Order

How to calculate On Hand Inventory Per Day

How to Calculate Purch Totals in purchase order's Totals Form