I need to modify Purchase Order Form, so user can select and save PO as PDF in destination folder
I created a new Button, so after user selects data and clicks the button, system creates a PDF file and saves it to the destination folder.
This is my code
public static void main(Args _args)
{
PurchTable purchTable,purchTable2, row;
PurchPurchaseOrderController purchPurchaseOrderController ;
PurchPurchaseOrderContract purchPurchaseOrderContract;
SrsReportRunImpl srsReportRun;
VendPurchOrderJour vendPurchOrderJour;
FormDataSource purchTable_ds;
str PDFName;
int tot = 0;
Args args ;
ReportName reportName = "PurchPurchaseOrder.ReportPRI";
;
if(_args.record().TableId == tableNum(PurchTable))
{
purchTable2 = _args.record();
purchTable_ds = purchTable2.dataSource();
}
if (purchTable_ds.anyMarked())
{
row = purchTable_ds.getFirst( 1, false );
info("a1");
while(row)
{
tot++;
info(row.PurchId);
args = new Args();
args.record(row);
select firstFast purchTable where purchTable.RecId == row.RecId ;
select firstFast vendPurchOrderJour where vendPurchOrderJour.PurchId == purchTable.PurchId ;
PDFName = strFmt("C:\\SharePDF\\%1.pdf",strReplace(purchTable.PurchId,'/','_'));
purchPurchaseOrderController = new PurchPurchaseOrderController();
purchPurchaseOrderController.parmReportName(ReportName);
purchPurchaseOrderContract = purchPurchaseOrderController.parmReportContract().parmRdpContract();
purchPurchaseOrderContract.parmRecordId(vendPurchOrderJour.RecId);
purchPurchaseOrderController.parmArgs(args);
srsReportRun = purchPurchaseOrderController.parmReportRun() as SrsReportRunImpl;
purchPurchaseOrderController.parmReportRun(srsReportRun);
purchPurchaseOrderController.parmReportContract().parmReportExecutionInfo(new SrsPrintMgmtExecutionInfo());
purchPurchaseOrderController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
purchPurchaseOrderController.parmReportContract().parmPrintSettings().overwriteFile(true);
purchPurchaseOrderController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
purchPurchaseOrderController.parmReportContract().parmPrintSettings().fileName(PDFName);
purchPurchaseOrderController.runReport();
row = purchTable_ds.getNext();
}
}
info(strFmt("%1",tot));
}
This code is running and will create a pdf file, but only for the last PO.
Any suggestions how to fix this problem? Thanks
This is has been solved. Thanks for All.
This is my complete Code
public static void main(Args _args)
{
PurchTable purchTable,purchTable2, row;
PurchPurchaseOrderContract purchPurchaseOrderContract;
VendPurchOrderJour vendPurchOrderJour;
FormDataSource purchTable_ds;
SRSPrintDestinationSettings settings;
SrsReportRunController controller ;
str folderPath;
dialog d;
DialogField dialogFilename;
str PDFName, FilePath;
int tot = 0;
Args args;
ReportName reportName = "PurchPurchaseOrder.ReportPRI";
PurchTable _PurchTable;
MultiSelectionHelper _helper = MultiSelectionHelper::construct();
;
d = new dialog();
d.caption("select a folder");
dialogFilename = d.addField(extendedTypeStr(FilePath));//add a field where you select your file in a specific path
d.run();
if(d.closedOk())
{
folderPath = dialogFileName.value();//return path file value
if(folderPath == '')
{
folderPath = 'C:\\SharePdf';
}
if(_args.record().TableId == tableNum(PurchTable))
{
purchTable2 = _args.record();
purchTable_ds = purchTable2.dataSource();
}
if (purchTable_ds.anyMarked())
{
row = purchTable_ds.getFirst( 1, false );
while(row)
{
tot++;
args = new Args();
select firstFast purchTable where purchTable.RecId == row.RecId ;
select firstFast vendPurchOrderJour where vendPurchOrderJour.PurchId == purchTable.PurchId ;
PDFName = strFmt("%2\\%1.pdf",strReplace(purchTable.PurchId,'/','_'), folderPath);
controller = new SrsReportRunController();
purchPurchaseOrderContract = new PurchPurchaseOrderContract();
controller.parmReportName(ReportName);
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
controller.parmShowDialog(false);
purchPurchaseOrderContract.parmRecordId(vendPurchOrderJour.RecId);
args.record(row);
controller.parmReportContract().parmRdpContract(purchPurchaseOrderContract);
controller.parmArgs(args);
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(PDFName);
controller.startOperation();
row = purchTable_ds.getNext();
}
}
info(strFmt("%1 Total",tot));
}
}