Kind regards, Adis
If this helped, please mark it as "Verified" for others facing the same issue
Keep in mind that it is possible to mark more than one answer as verified
reportBytes = srsProxy.renderReportToByteArray('PurchLineExcel.Report', // report design name
paramArray,
SRSReportFileFormat::Excel,
'PurchaseLines.xlsx'
);
class summaryReportController extends SrsReportRunController
{
// Main method to trigger the report generation
public static void main(Args _args)
{
summaryReportController controller = new summaryReportController();
controller.parmReportName(ssrsReportStr(summaryReport, Report)); // Specify the report name
controller.startOperation();
}
// Override startOperation to customize report export behavior
public SysOperationStartResult startOperation()
{
SrsReportRunController controller = new SrsReportRunController();
SRSPrintDestinationSettings printSettings;
SRSProxy srsProxy = new SRSProxy();
str reportNameExcel = 'PurchLineExcel.Report'; // SSRS report name
str fileName = 'PurchaseLines.xlsx'; // Excel file name
System.Byte[] reportBytes;
System.IO.MemoryStream memoryStream;
// Set the report name
controller.parmReportName(reportNameExcel);
// 1. Configure print destination for Excel
printSettings = controller.parmReportContract().parmPrintSettings();
printSettings.printMediumType(SRSPrintMediumType::File); // Output to file
printSettings.fileFormat(SRSReportFileFormat::Excel); // Excel file format
printSettings.overwriteFile(true); // Overwrite if file exists
printSettings.parmFileName(fileName); // Set file name
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] paramArray;
paramArray = new Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[0]();
// 2. Render the report as byte array
reportBytes = srsProxy.renderReportToByteArray('PurchLineExcel.Report', // report design name
paramArray,
SRSReportFileFormat::Excel,
'PurchaseLines.xlsx'
);
// 3. Send the Excel report to the client
if (reportBytes)
{
memoryStream = new System.IO.MemoryStream(reportBytes);
File::SendFileToUser(
memoryStream,
fileName,
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
}
else
{
error("Failed to generate the Purchase Line report.");
}
return 0;
}
}
class SummaryReportDP extends SrsReportDataProviderBase
{
PurchLine purchLine;
PurchTable purchTable;
SummaryReportTemp summaryReportTemp; // Temporary table to store report data
[ SRSReportDataSetAttribute(tableStr(summaryReportTemp)) ]
public summaryReportTemp getsummaryReportTemp()
{
return summaryReportTemp;
}
public void processReport()
{
Map poSummaryMap = new Map(Types::String, Types::Record);
summaryReportTemp tempRec;
str key;
// Step 1: Aggregate quantities, prices, amounts per PurchId
while select purchLine
join purchTable
where purchTable.PurchId == purchLine.PurchId
{
key = purchLine.PurchId;
if (poSummaryMap.exists(key))
{
tempRec = poSummaryMap.lookup(key);
tempRec.PurchQty += purchLine.PurchQty;
tempRec.LineAmount += purchLine.LineAmount;
tempRec.PurchPrice += purchLine.PurchPrice;
}
else
{
tempRec.clear();
tempRec.PurchId = purchLine.PurchId;
tempRec.PurchQty = purchLine.PurchQty;
tempRec.LineAmount = purchLine.LineAmount;
tempRec.PurchPrice = purchLine.PurchPrice;
tempRec.VendorId = purchTable.OrderAccount;
tempRec.VendorName = VendTable::find(purchTable.OrderAccount).name();
poSummaryMap.insert(key, tempRec);
}
}
// Step 2: Insert aggregated records into the temp table
MapEnumerator enumerator = poSummaryMap.getEnumerator();
while (enumerator.moveNext())
{
tempRec = enumerator.currentValue();
tempRec.insert();
}
}
}
Kind regards, Adis
If this helped, please mark it as "Verified" for others facing the same issue
Keep in mind that it is possible to mark more than one answer as verified
Abhilash Warrier
565
Martin Dráb
536
Most Valuable Professional
André Arnaud de Cal...
402
Super User 2025 Season 1