Skip to main content

Notifications

ER in memory!

In the following link you can consult the official Microsoft documentation on how to develop a report using the Electronic Reports functionality:

https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/analytics/er-quick-start1-new-solution#ModifySourceCode

But what if we want to send this report to some external service? Can we get the content of the report in a variable?

The answer is YES!!

I leave you a code fragment that launches a GER report obtaining the content in a ByteArray (byteER) variable:

using Microsoft.Dynamics365.LocalizationFramework;
/// 
/// The electronic reporting service class for a custom ER report
/// 
class CustomErReportService extends SysOperationServiceBase
{
    public const str ERModelDataSourceName = 'model';
    public const str DefaultExportedFileName = 'Custom report';
    public const str ParametersDataSourceName = 'RunTimeParameters';

    /// 
    /// Generates report by using Electronic reporting framework
    /// 
    /// The Custom report contract
    public void generateReportByGER(CustomErReportContract _contract)
    {
        ERFormatMappingId formatMappingId;
        CustomErReportDP  dataProvider;
        dataProvider = CustomErReportDP::construct();
        formatMappingId = _contract.parmFormatMapping();
        if (formatMappingId)
        {
            try
            {
                ERIModelDefinitionParamsAction parameters = new             ERModelDefinitionParamsUIActionComposite()
                    .add(new ERModelDefinitionObjectParameterAction(ERModelDataSourceName, ParametersDataSourceName, _contract, true));

                // Call ER to generate the report.
                ERIFormatMappingRun formatMappingRun = ERObjectsFactory::createFormatMappingRunByFormatMappingId(formatMappingId, DefaultExportedFileName);
                runner.parmShowPromptDialog(false);
                runner.withShowDestinationTab(false);

                ERFileDestinationMemory fileDestinationMemory = new ERFileDestinationMemory();
                runner.withFileDestination(fileDestinationMemory);

                str stream = runner.withParameter(parameters).run();
                System.Byte[] byteER = fileDestinationMemory.GetByteArray();
                }
            }
            catch
            {
                // An error occurred while exporting data.
                error("@SYP4861341");
            }
        }
        else
        {
            // There is no data available.
            info("@SYS300117");
        }
    }
}

Comments

*This post is locked for comments