Monday, December 29, 2014

Getting number of recrods present in a query

If you want to get the total number of records from a query run object, which can be used to set total count in a progress bar (progress indication framework).

Solution: Use SysQuery::countloop([QueryRun _queryRun]). this will return the total number of records in a query object

Wednesday, December 24, 2014

Generating SSRS report in PDF via code X++

Following is a sample code for generating SSRS report in PDF format using X++ code. This sample code generates Purchase order confirmation report in PDF format and saves it into specified location.


PSAPurchaseOrderController poConfirmationController;
PurchPurchaseOrderContract purchPOContract;
SRSReportExecutionInfo     reportExecutionInfo;
Args                       args = new Args();
SrsReportRunImpl           srsReportRun;
VendPurchOrderJour         vendPurchOrderJour;
ReportName                 reportName = ssrsReportStr(PSAPurchaseOrder, Report);

str                        fileName;
;

select firstOnly vendPurchOrderJour
order by RecId desc
where vendPurchOrderJour.PurchId == '';//Replace with PurchOrder Id

if (!vendPurchOrderJour)
return '';


args.record(vendPurchOrderJour);
poConfirmationController= PSAPurchaseOrderController::construct();
poConfirmationController.parmArgs(args);
poConfirmationController.parmReportName(reportName);
reportExecutionInfo = poConfirmationController.parmReportContract().parmReportExecutionInfo();
purchPOContract= poConfirmationController.parmReportContract().parmRdpContract();


purchPOContract.parmRecordId(vendPurchOrderJour.RecId); // Record id must be passed otherwise the report will be empty

poConfirmationController.parmArgs(args);srsReportRun = poConfirmationController.parmReportRun() as SrsReportRunImpl;


fileName = System.IO.Path::Combine(WinAPIServer::getTempPath(), strFmt('purchConfirmation_%1.pdf', _purchId));
poConfirmationController.parmReportRun(srsReportRun);
poConfirmationController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
poConfirmationController.parmReportContract().parmPrintSettings().overwriteFile(true);


poConfirmationController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
poConfirmationController.parmReportContract().parmPrintSettings().fileName(fileName);

poConfirmationController.runReport();