Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to print invoice (Electronic Reporting) using code?

(0) ShareShare
ReportReport
Posted on by 737

Hello, I have a problem with electronic reporting printing..

The requirement is that the user has invoice prints configured in electroning reporting (CustFormletterParameters), which he starts with "Use print management". He has the destinations for electronically reporting set in ERFormatDestination.


In general, the point is, user can select different format desitnation, but they are supported at the same time only through one button "Use print management".
I want to add two additional buttons that will have a fixed destination set, that is, for example, button1 "printer", button2 "email", and the standard button "screen". Buttons are supposed to use the settings in print management, but are supposed to skip the settings in ERFormatDestination - this is supposed to be set hard for the specific button.
This way, the user won't run three destinations from the standard button each time, but will have a choice of what to select.

I hope I have clearly described my problem.

Did anyone have any suggestions or materials/articles that can be helpful to me?

Thank you in advance

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to print invoice (Electronic Reporting) using code?

    I have come to the point where the problem seems to have been solved, except for one issue. The solution I shared above allows you to select from a list, a particular formatMappingId. The requirement is that this ID be automatically selected based on the settings in print management. Could someone please suggest where I can look for this? Or what is the piece of code that is responsible for this in standard invoice printing?

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to print invoice (Electronic Reporting) using code?

    I decided to try to generate a printout according to the documentation:
    https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/analytics/er-quick-start1-new-solution

    Service class:

    using Microsoft.Dynamics365.LocalizationFramework;
    
    class InvoiceErReportService extends SysOperationServiceBase
    {
        public const str ERModelDataSourceName = 'invoice model';
        public const str DefaultExportedFileName = 'Invoice';
        public const str ParametersDataSourceName = 'RunTimeParameters';
    
        public void generateReportByGER()
        {
            ERFormatMappingId formatMappingId;
            INT_InvoiceErReportDP dataProvider;
            dataProvider = INT_InvoiceErReportDP::construct();
            formatMappingId = 5637149076;
    
            if (formatMappingId)
            {
                try
                {
                    // Call ER to generate the report.
                    ERIFormatMappingRun formatMappingRun = ERObjectsFactory::createFormatMappingRunByFormatMappingId(formatMappingId, DefaultExportedFileName);
                    formatMappingRun.parmShowPromptDialog(false);
                    var formatMappingRunWithAction = formatMappingRun as ERIFormatMappingRunWithDestinationAction;
                    formatMappingRunWithAction.withDestinationAction(ERDestinationAction::View);
                    formatMappingRun.run();
    
                }
                catch
                {
                    // An error occurred while exporting data.
                    error("@SYP4861341");
                }
            }
            else
            {
                // There is no data available.
                info("@SYS300117");
            }
        }
    
    }

    Controller class:

    class InvoiceErReportController extends ERFormatMappingRunBaseController
    {
        public static void main(Args args)
        {
            InvoiceErReportController operation;
            operation = new InvoiceErReportController(classStr(InvoiceErReportService), methodStr(InvoiceErReportService, generateReportByGER), SysOperationExecutionMode::Asynchronous);
            operation.startOperation();
        }
    
    }

    DP class:

    public class InvoiceErReportDP
    {
        public static InvoiceErReportDP construct()
        {
            InvoiceErReportDP dataProvider;
            dataProvider = new InvoiceErReportDP();
            return dataProvider;
        }
    
    }

    I get the following errors every time the formatMappingRun.run() method is called;

    6012.errors.png

    What else is missing?
    The standard solution works and the printout is generated, but I can't trigger the generation through the additional button.

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to print invoice (Electronic Reporting) using code?

    The error message appears on this code:

    ERIFormatMappingRun formatMappingRun = ERObjectsFactory::createFormatMappingRunByFormatMappingId(_contract.parmERFormatMappingId())
                    .withParameter(parameters)
                    .withCreatingObjectParameter(EInvoiceConstants::ERModelNameInvoice, 'O_'   classStr(OIOUBLReportController), OIOUBLReportController)
                    .withFileDestination(_contract.getFileDestination())
                    .withFormatMappingRunJobCaption(formatMappingRunJobCaption)
                    .withRunInBatchMode(true)
                    .withIntegrationPoint(new ERIntegrationPointFactory().WithTableRecordsIntegrationPoint(tableId2Name(tableId)).ToIntegrationPoint());

    Microsoft.Dynamics.Ax.Xpp.ErrorException
    HResult=0x80131500
    Message=Expected format mapping has not been found.
    Source=Dynamics.AX.ElectronicReporting
    StackTrace:
    at Dynamics.AX.Application.ERFormatMappingRun.new(ERFormatMappingTable _runFormatMapping, ERTextFormatTable _runFormat, String _fileName, Boolean @_fileName_IsDefaultSet)
    at Dynamics.AX.Application.ERFormatMappingRun.new(ERFormatMappingTable _runFormatMapping, ERTextFormatTable _runFormat)
    at Dynamics.AX.Application.ERFormatMappingRun..ctor(ERFormatMappingTable , ERTextFormatTable )
    at Dynamics.AX.Application.ERFormatMappingRun.constructBySolutionTable(ERSolutionTable _solutionTable)
    at Dynamics.AX.Application.ERFormatMappingRun.constructBySolutionVersion(ERSolutionVersionTable _solutionVersion)
    at Dynamics.AX.Application.ERFormatMappingRun.initItemsBySolutionRunSettings(ERSolutionTable _solutionTable, Boolean _forceRunDraft, Boolean @_forceRunDraft_IsDefaultSet)
    at Dynamics.AX.Application.ERFormatMappingRun.initItemsBySolutionRunSettings(ERSolutionTable _solutionTable, Boolean _forceRunDraft)
    at Dynamics.AX.Application.ERFormatMappingRun.constructByFormatMappingId(Int64 _formatMappingId, String _fileName, Boolean _showPromptDialog, Boolean _showInfologMessage, Boolean _forceRunDraft, Boolean @_fileName_IsDefaultSet, Boolean @_showPromptDialog_IsDefaultSet, Boolean @_showInfologMessage_IsDefaultSet, Boolean @_forceRunDraft_IsDefaultSet)
    at Dynamics.AX.Application.ERFormatMappingRun.constructByFormatMappingId(Int64 _formatMappingId, String _fileName, Boolean _showPromptDialog, Boolean _showInfologMessage, Boolean _forceRunDraft)
    at Dynamics.AX.Application.ERObjectsFactory.createFormatMappingRunByFormatMappingId(Int64 _formatMappingId, String _fileName, Boolean _showPromptDialog, Boolean _showInfologMessage, Boolean _forceRunDraft, Boolean @_fileName_IsDefaultSet, Boolean @_showPromptDialog_IsDefaultSet, Boolean @_showInfologMessage_IsDefaultSet, Boolean @_forceRunDraft_IsDefaultSet)
    at Dynamics.AX.Application.ERObjectsFactory.createFormatMappingRunByFormatMappingId(Int64 _formatMappingId)
    at Dynamics.AX.Application.my_EInvoiceGenerationService.`my_generateEInvoice(EInvoiceGenerationDataContract _contract) in xppSource://Source/Test\AxClass_my_EInvoiceGenerationService.xpp:line 58
    at Dynamics.AX.Application.my_EInvoiceGenerationService.my_generateEInvoice(EInvoiceGenerationDataContract _contract)
    at Dynamics.AX.Application.my_EInvoiceGenerationController.`main(Args _args) in xppSource://Source/Test\AxClass_my_EInvoiceGenerationController.xpp:line 23
    at Dynamics.AX.Application.my_EInvoiceGenerationController.main(Args _args)
    at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[ parameters)

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to print invoice (Electronic Reporting) using code?

    Thank you for the quick reply. However, it is not clear to me all the time....

    I did some debugging of the standard solution and after some time I found the EInvoiceGenerationService class.
    For testing purposes, I copied it, created the corresponding controller to see if it was responsible for generating the ER invoice for the sales order. Unfortunately, after running the class, I received the following error: "Expected format mapping has not been found".

    Conttroller class:

    public static void main(Args _args)
        {
            var contract = new EInvoiceGenerationDataContract();
            contract.initFromArgs(_args);
    
            var service = new my_EInvoiceGenerationService();
            service.my_generateEInvoice(contract);
        }

    I honestly feel a little lost.... Could someone suggest something or give a hint where or how to find a solution and am I on the right way?

    Thanks a lot.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 on at
    RE: How to print invoice (Electronic Reporting) using code?

    Hi, Please check this thread

    community.dynamics.com/.../electronic-reporting-ger-new-report-run-by-button

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans