PO Confirmation Report Issue.

Hi Experts,

I am using D 365.

My requirement is loop through the PO confirmation Journals based on the posting date in a specific date range from parameters and save the PO confirmation reports in that date range to PDF. The code is generating and saving in PDF files based on my input in the dialog. But, for eg: I gave 1st March to 10th March and it has 10 PO confirmations. The code is not generating all the 10 instead it is generating randomly 7 at one time and 8 at another time etc.

Here is the code:

class POConfirmationSeriesReportHandler extends RunBase
{
// User Input fields
DialogField formDateDialogField, toDateDialogField;
DialogField purchPrintScreenField;

// Variables to store user input
TransDate fromDate, toDate;
NoYesId purchPrintScreen;
// pack() and unpack() methods are used to load the last value from user

public container pack()
{
return conNull();
}

public boolean unpack(container packedClass)
{
return true;
}

// Dialog method to capture runtime user inputs for customer details
public Object dialog()
{
Dialog dialog = super();

// Set a title for dialog
dialog.caption( 'PO Confirmation Series Report Dialog');

// Add a new field to Dialog
formDateDialogField = dialog.addField(extendedTypeStr(TransDate), 'From Date');
toDateDialogField = dialog.addField(extendedTypeStr(TransDate), 'To Date');
purchPrintScreenField = Dialog.addField(extendedTypeStr(NoYesId), 'Print');

return dialog;
}

// Retrieve values from Dialog
public boolean getFromDialog()
{
fromDate = formDateDialogField.value();
toDate = toDateDialogField.value();
purchPrintScreen = purchPrintScreenField.value();
return super();
}

public void run()
{
SrsReportRunController ssrsController = new SrsReportRunController();
PurchPurchaseOrderContract purchPurchaseOrderContract = new PurchPurchaseOrderContract();
SRSPrintDestinationSettings printerSettings;
VendPurchOrderJour VendPurchOrderJour;
int i = 1;
Temptable tempTable;

if(purchPrintScreen == NoYes::Yes)
{
select firstonly tempTable;

if(!tempTable)
{
tempTable.Counter = 1;
tempTable.insert();
}
else
{
i = tempTable.Counter;
}
//select the latest record based on create date
while select VendPurchOrderJour
order by VendPurchOrderJour.createdDateTime DESC
where VendPurchOrderJour.PurchOrderDate >= fromDate
&& VendPurchOrderJour.PurchOrderDate <= toDate
{
i++;
ssrsController = null;
purchPurchaseOrderContract = null;
ssrsController = new SrsReportRunController();
purchPurchaseOrderContract = new PurchPurchaseOrderContract();
//info(strFmt("%1", VendPurchOrderJour.RecId));
//tell the controller the report to run (filename, design name)
ssrsController.parmReportName(ssrsReportStr(Purchpurchaseorder, Report));
//define how we want to execute the report (right now or batch style)
ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
//hide the report dialog
ssrsController.parmShowDialog(false);
ssrsController.parmLoadFromSysLastValue(false);

//we need to populate the required parms for the current sales order controller
purchPurchaseOrderContract.parmRecordId(VendPurchOrderJour.RecId);
purchPurchaseOrderContract.parmDocumentTitle("Purchase order");

//link the contract to the controller so we know how to run the dp
ssrsController.parmReportContract().parmRdpContract(purchPurchaseOrderContract);

if(purchPrintScreen == NoYes::Yes)
{
//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(false);

printerSettings.fileName(@"c:\\" + strFmt("%1_%2",VendPurchOrderJour.PurchOrderDocNum, i) + ".pdf");

}
//run & save the report
ssrsController.startOperation();
}
ttsbegin;
if(tempTable)
{
tempTable.selectForUpdate(true);
tempTable.Counter = i;
tempTable.update();
}
ttscommit;
}
else
{
//select the latest record based on create date
while select VendPurchOrderJour
order by VendPurchOrderJour.createdDateTime DESC
where VendPurchOrderJour.PurchOrderDate >= fromDate
&& VendPurchOrderJour.PurchOrderDate <= toDate
{
ssrsController = null;
purchPurchaseOrderContract = null;
ssrsController = new SrsReportRunController();
purchPurchaseOrderContract = new PurchPurchaseOrderContract();
info(strFmt("%1", VendPurchOrderJour.RecId));
//tell the controller the report to run (filename, design name)
ssrsController.parmReportName(ssrsReportStr(Purchpurchaseorder, Report));
//define how we want to execute the report (right now or batch style)
ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
//hide the report dialog
ssrsController.parmShowDialog(false);
ssrsController.parmLoadFromSysLastValue(false);

//we need to populate the required parms for the current sales order controller
purchPurchaseOrderContract.parmRecordId(VendPurchOrderJour.RecId);
purchPurchaseOrderContract.parmDocumentTitle("Purchase order");

//link the contract to the controller so we know how to run the dp
ssrsController.parmReportContract().parmRdpContract(purchPurchaseOrderContract);

//run & save the report
ssrsController.startOperation();
}
}
}

public static void main(Args _args)
{
POConfirmationSeriesReportHandler POConfirmationSeriesReport = new POConfirmationSeriesReportHandler();

// Prompt the dialog, if user clicks in OK it returns true
if (POConfirmationSeriesReport.prompt())
{
POConfirmationSeriesReport.run();
}
}

}

Parents
No Data
Reply Children
No Data
Related
Recommended