web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Electronic Reporting - Print several documents from one query

(3) ShareShare
ReportReport
Posted on by 49
Hello,
 
I created an Electronic Report and am calling it via a controller class (+ service and contract class).
The requirement is two fold:
One button needs to print a selected record,
while the second button need to print a specified range, that can be adjusted.
 
The class I created gets the query correctly to the ER model mapping (debugger shows the filtered values in my Record list).
I then bind the record list to my MM record list, which I then bind to my Format mapping document.
 
The debugger shows all records for all 3 instances, but the print at the end only results in one document created.
Is this not an option with electronic reporting currently, or how do I have to setup my ER files?
 
Contract:
/// <summary>
/// This is the data contract class for ER loading slip report
/// </summary>
[DataContractAttribute]
[DataContract]
public class AVAERLoadingSlipReportContractCls extends ERFormatMappingRunBaseContract
{
    str packedQuery;
    ERFormatMappingId formatMapping;

    /// <summary>
    /// parm method for packedQuery
    /// </summary>
    /// <param name = "_packedQuery">str</param>
    /// <returns>str</returns>
    [DataMemberAttribute, AifQueryTypeAttribute('_packedQuery', queryStr("AVALoadingSlipQuery"))]
    public str parmPackedQuery(str _packedQuery = packedQuery)
    {
        packedQuery = _packedQuery;

        return packedQuery;
    }

    /// <summary>
    /// parm method for format mapping
    /// </summary>
    /// <param name = "_formatMapping">ERFormatMappingId</param>
    /// <returns>ERFormatMappingId</returns>
    [DataMemberAttribute('FormatMapping'), SysOperationLabelAttribute(literalstr("@ElectronicReporting:FormatMapping")), SysOperationHelpTextAttribute(literalstr("@ElectronicReporting:FormatMapping"))]
    public ERFormatMappingId parmFormatMapping(ERFormatMappingId _formatMapping = formatMapping)
    {
        formatMapping = _formatMapping;

        return formatMapping;
    }

    // This method unpacks the query and returns it as query object.
    public Query getQuery()
    {
        return new Query(SysOperationHelper::base64Decode(packedQuery));
    }

    // This method takes a query object, encodes it and stores the packed query.
    public void setQuery(Query _query)
    {
        packedQuery = SysOperationHelper::base64Encode(_query.pack());
    }

    /// <summary>
    /// initFromArgs method
    /// </summary>
    /// <param name = "_args">Args</param>
    public void initFromArgs(Args _args)
    {
        FormDataSource fd_whsLoadTable = _args.record().dataSource();
        MultiSelectionHelper helper = MultiSelectionHelper::construct();
        WHSLoadTable whsLoadTable;
        Query query = new Query('AVALoadingSlipQuery');
        QueryBuildDataSource qbdsWHSLoadTable = query.dataSourceTable(tablenum(WHSLoadTable));
        QueryBuildRange qbrWHSLoadId;
                    
        if(fd_whsLoadTable)
        {
            qbrWHSLoadId = SysQuery::findOrCreateRange(qbdsWHSLoadTable, FieldNum(WHSLoadTable, LoadId));
            qbrWHSLoadId.value('');

            helper.parmDatasource(fd_whsLoadTable);

            whsLoadTable = helper.getFirst();
            while (whsLoadTable.RecId != 0)
            {
                qbrWHSLoadId.value(queryRangeConcat(qbrWHSLoadId.value(), whsLoadTable.LoadId));
                whsLoadTable = helper.getNext();
            }
        }

        this.setQuery(query);
        this.parmFormatMapping(WHSParameters::find().AVAERLoadingSlipFormatMapping);

    }

}
Service:
using Microsoft.Dynamics365.LocalizationFramework;

/// <summary>
/// service class for ER loading slip report
/// </summary>
public class AVAERLoadingSlipReportServiceCls extends SysOperationServiceBase
{
    public const str DefaultExportedFileName = "@AVAExtension:ER_LoadingSlipDocument";
    public const str ERModelDataSourceName = 'model';
    public const str ParametersDataSourceName = 'RunTimeParameters';

    /// <summary>
    /// Generates report by using Electronic reporting framework
    /// </summary>
    /// <param name = "_contract">The object non conformance report contract</param>
    public void generateReport(AVAERLoadingSlipReportContractCls _contract)
    {
        ERFormatMappingId formatMappingId;
        QueryBuildDataSource qbds = _contract.getQuery().dataSourceNo(1);

        formatMappingId = _contract.parmFormatMapping();

        if (formatMappingId)
        {
            try
            {
                ERIModelDefinitionParamsAction parameters = new ERModelDefinitionParamsUIActionComposite().add(new ERModelDefinitionDatabaseContext().addQuery(qbds.file(), _contract.getQuery()));
                
                // Call ER to generate the report.
                ERIFormatMappingRun formatMappingRun = ERObjectsFactory::createFormatMappingRunByFormatMappingId(formatMappingId, DefaultExportedFileName, true);
                formatMappingRun.withParameter(parameters);

                formatMappingRun.run();

            }
            catch
            {
                // An error occurred while exporting data.
                error("@SYP4861341");
            }
        }
        else
        {
            // There is no data available.
            info("@SYS300117");
        }
    }

}
Controller:
/// <summary>
/// Controller class for ER Loading slip report
/// </summary>
public class AVAERLoadingSlipReportControllerCls extends ERFormatMappingRunBaseController
{
    /// <summary>
    /// The main entrance of the controller
    /// </summary>
    /// <param name = "args">The arguments</param>
    public static void main(Args args)
    {
        if(!WHSParameters::find().AVAERLoadingSlipFormatMapping)
        {
            throw Error(strFmt("@AVAExtension:ER_LoadingSlipReportError", "@WAX5406", "@SYS80071", "@AVAExtension:ER_LoadingSlipDocument", "@AVAExtension:ER_LoadingSlipFormat"));
        }
        
        AVAERLoadingSlipReportControllerCls operation;
        operation = new AVAERLoadingSlipReportControllerCls(
            classStr(AVAERLoadingSlipReportServiceCls),
            methodStr(AVAERLoadingSlipReportServiceCls, generateReport),
            SysOperationExecutionMode::Synchronous);

        AVAERLoadingSlipReportContractCls contract = operation.getDataContractObject();
        
        contract.initFromArgs(args);

        //operation.parmShowDialog(true);
        operation.startOperation();
    }

    /// <summary>
    /// Gets caption of the dialog.
    /// </summary>
    /// <returns>Caption of the dialog</returns>
    public ClassDescription defaultCaption()
    {
        ClassDescription batchDescription;
        batchDescription = "@AVAExtension:ER_LoadingSlipDocument";
        return batchDescription;
    }

    public boolean showPrintSettings()
    {
        return true;
    }

}
 
Model:
 
Model Mapping:
 
Format mapping:
The format Mapping only contains LoadId, since this is only a test version for the coding
 
Categories:
I have the same question (0)
  • Verified answer
    Thimo F. Profile Picture
    49 on at
    Quick update from my side for other people that might look for this:
    The issue got resolved for me when I added a Root folder and moved the report into that folder.
    I didn't change any code for this or any other mapping bindings.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 699

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 582 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 493

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans