最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

用X++生成财务报告 / Generate financial report in X++

网络文摘 William 978浏览 0评论

Purpose

The purpose of this blog post is to demonstrate how can we generate a financial report in X++ and download it as a file.

Product

Dynamics 365 Finance.

Description

Please find the code snippet below which can be used to generate a financial report in X++. The code generates the report in XML format. The same code can be used to export the report in Excel and XPS file formats. Once generated the code allows the user to download the generated report.
public static void main(Args _args)
{
	financialReportVersion financialReportVersion;
	FinancialReports       financialReports;
	PeriodEnd              periodEndDate;
	str                    reportName;
	str                    fileContent;
	const str              fileName = 'FinancialReport.xml';

	reportName = "12 Month Rolling Single Column Income Statement - Default";
	periodEndDate = FiscalCalendarYear::findYearByCalendarDate(
		Ledger::fiscalCalendar(CompanyInfo::find().RecId), systemDateGet()).EndDate;
	
	select firstonly financialReportVersion
		order by recid desc
	join financialReports
		where financialReports.DesignId==financialReportVersion.DesignId
			&& financialReports.reportName == reportName;
	
	FinancialReportingIReportExport reportExporter = new FinancialReportingReportExport();
	System.Text.Encoding encodingGB18030 = System.Text.Encoding::GetEncoding("utf-8");
	
	if (!financialReports.DesignId)
	{
		throw error(strfmt("Design not found for Report %1", reportName));
	}
	
	System.IO.Stream stream = reportExporter.GenerateAndExportReport(
		financialReports.DesignId,
		curExt(),
		periodEndDate,
		FinancialReportingReportExportFormat::Xml,
		encodingGB18030);
	
	if (stream == null)
	{
		throw error(strfmt("Stream is empty for Report %1 period %2",
			reportName, periodEndDate));
	}
	
	System.IO.StreamReader sReader = new System.IO.StreamReader(stream);
	fileContent = sReader.ReadToEnd();
	File::SendStringAsFileToUser(fileContent, fileName);
}
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址