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

Community site session details

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

Electronic Reporting via Code - Include Model Mapping User Input Parameters in Print dialog

(0) ShareShare
ReportReport
Posted on by 20
Hello,
 
I created a Electronic Report that gets called via code (Service, controller and contract class).
I also created the Model, model mapping and format Mapping ER files for the report.
As far as my test went the selected record gets filtered for ER and it works in general well.
But what is not working, is getting the User input parameters from the model mapping.
The ones from the format mapping are added correctly.
 
So: How do I add model mapping Input parameters to my dialog via code?
 
I assume I have to add them as a parameter to the formatMappingRun, but the Intrastat example I used is pretty confusing with all its methods jumping around.
I also was wondering if the was a easy way I just didn't see.
If there is no easy way I would appreciate an example code that I can try to understand.
Also, since I am pretty inexperienced in writing ER classes via code, if there are glaring mistakes, please point them out, ty.
 
Contract class:
 
/// <summary>
/// This is the data contract class for ER inventory transfer packing slip report
/// </summary>
[DataContract]
public class AVAInventTransferPackingSlipReportContractCls extends ERFormatMappingRunBaseContract
{
    str                 packedQuery;
    ERFormatMappingId   formatMapping;
    Filename            fileName;
    NoYes               showDestination;

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

        return packedQuery;
    }

    // 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>
    /// 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;
    }

    /// <summary>
    /// Parm method for the file name.
    /// </summary>
    /// <param name = "_fileName">Filename for print.</param>
    /// <returns>The vendor account number.</returns>
    [DataMemberAttribute('FileName'), SysOperationControlVisibilityAttribute(false)]
    public Filename parmFileName(Filename _fileName = fileName)
    {
        fileName = _fileName;
        return fileName;
    }

    [DataMember,
        SysOperationLabel(identifierStr("Show destination"))]//This of course must be a label
    public NoYes parmShowDestination(NoYes _showDestination = showDestination)
    {
        showDestination = _showDestination;
        return showDestination;
    }

    /// <summary>
    /// initFromArgs method
    /// </summary>
    /// <param name = "_args">Args</param>
    public void initFromArgs(Args _args)
    {
        FormRun formRun = _args.caller();
        FormDataSource fd_inventTransferJour = formRun.dataSource();
        MultiSelectionHelper helper = MultiSelectionHelper::construct();
        InventTransferJour inventTransferJour;
        Query query = fd_inventTransferJour.query();
        QueryBuildDataSource qbdsInventTransferJour = query.dataSourceTable(tablenum(InventTransferJour));
        QueryBuildRange qbrInventTransferJourRecId;
                    
        qbrInventTransferJourRecId = SysQuery::findOrCreateRange(qbdsInventTransferJour, FieldNum(InventTransferJour, RecId));
        qbrInventTransferJourRecId.value(SysQuery::valueUnlimited());

        helper.parmDatasource(fd_inventTransferJour);

        inventTransferJour = helper.getFirst();
        while (inventTransferJour.RecId != 0)
        {
            qbrInventTransferJourRecId.value(queryRangeConcat(qbrInventTransferJourRecId.value(), inventTransferJour.RecId));
            inventTransferJour = helper.getNext();
        }

        this.setQuery(query); 
    }

}
 
 
Service class:
 
using Microsoft.Dynamics365.LocalizationFramework;
using SL = Microsoft.Dynamics365.LocalizationFramework.XppSupportLayer;


/// <summary>
/// service class for ER inventory transfer packing slip report
/// </summary>
public class AVAInventTransferPackingSlipReportServiceCls extends SysOperationServiceBase
{
    public const str ERModelDataSourceName = 'model';
    public const str ParametersDataSourceName = 'RuntimeParameters';
    Map                                 mapERParametersWithDialogs;
    Map                                 mapERParametersValues;

    /// <summary>
    /// start method for controller
    /// </summary>
    /// <param name = "_contract">AVAInventTransferPackingSlipReportContractCls</param>
    public void runReport(AVAInventTransferPackingSlipReportContractCls _contract)
    {
        this.executeERReport(_contract);
    }

    /// <summary>
    /// ER execution method
    /// </summary>
    /// <param name = "_contract">AVAInventTransferPackingSlipReportContractCls</param>
    public void executeERReport(AVAInventTransferPackingSlipReportContractCls _contract)
    {
        if(_contract.parmFormatMapping())
        {
            try
            {
                this.generateERReport(_contract);
            }
            catch
            {
                // An error occurred while exporting data.
                error("@SYP4861341");
            }
        }
        else
        {
            // There is no data available.
            info("@SYS300117");
        }
    }

    /// <summary>
    /// Generates report by using Electronic reporting framework
    /// </summary>
    /// <param name = "_contract">The object inventory transfer packing slip report contract</param>
    public void generateERReport(AVAInventTransferPackingSlipReportContractCls _contract)
    {
        ERIFormatMappingRun formatMappingRun = this.createFormatMappingRun(_contract);

        formatMappingRun.run();
    }

    /// <summary>
    /// creates the format mapping run for contract
    /// </summary>
    /// <param name = "_contract">AVAInventTransferPackingSlipReportContractCls</param>
    /// <returns>ERIFormatMappingRun</returns>
    public ERIFormatMappingRun createFormatMappingRun(AVAInventTransferPackingSlipReportContractCls _contract)
    {
        ERIFormatMappingRun formatMappingRun = ERObjectsFactory::createFormatMappingRunWithParametersByFormatMappingId(
                    _contract.parmFormatMapping(),
                    _contract.parmFileName(),
                    this.showPromptDialog(_contract.parmShowDestination()),
                    this.showInfolog(),
                    this.forceRunDraft());

        formatMappingRun.withShowBatchTab(false);
        formatMappingRun.withShowDestinationTab(_contract.parmShowDestination() == NoYes::Yes);

        this.initFormatMappingRunOptionalParameters(formatMappingRun, _contract);

        return formatMappingRun;
    }

    /// <summary>
    /// adds parameters to format mapping run
    /// </summary>
    /// <param name = "_formatMapingRun">ERIFormatMappingRun</param>
    /// <param name = "_contract">AVAInventTransferPackingSlipReportContractCls</param>
    public void initFormatMappingRunOptionalParameters(ERIFormatMappingRun _formatMapingRun, AVAInventTransferPackingSlipReportContractCls _contract)
    {
        ERIModelDefinitionParamsAction  parameters = new ERModelDefinitionParamsUIActionComposite()
            //.add(this.getERModelDefinitionInputParameters(_contract))
            .add(this.getERModelDefinitionDatabaseContext(_contract));

        _formatMapingRun.withParameter(parameters);
    }

    /// <summary>
    /// <c>ERModelDefinitionDatabaseContext</c>
    /// </summary>
    /// <returns><c>ERModelDefinitionDatabaseContext</c></returns>
    protected ERModelDefinitionDatabaseContext getERModelDefinitionDatabaseContext(AVAInventTransferPackingSlipReportContractCls _contract)
    {                                    
        QueryBuildDataSource qbds = _contract.getQuery().dataSourceNo(1);

        return new ERModelDefinitionDatabaseContext().addQuery(qbds.file(), _contract.getQuery());
    }

    /// <summary>
    /// Gets <c>ERModelDefinitionDatabaseContext</c>
    /// </summary>
    /// <param name = "_contract">AVAInventTransferPackingSlipReportContractCls</param>
    /// <returns><c>ERModelDefinitionDatabaseContext</c></returns>
    protected ERModelDefinitionInputParametersAction getERModelDefinitionInputParameters(AVAInventTransferPackingSlipReportContractCls _contract)
    {
        ERModelDefinitionInputParametersAction retVal = new ERModelDefinitionInputParametersAction();

        var mapERParametersEnumerator = mapERParametersValues.getEnumerator();
        var formatMappingId  = _contract.parmFormatMapping();

        while (mapERParametersEnumerator.moveNext())
        {
            str currentKey = mapERParametersEnumerator.currentKey().ToString();
            if (strScan(currentKey, int642Str(formatMappingId), 1, strLen(currentKey)) > 0)
            {
                retVal.addParameter(this.getERParameterFromKey(formatMappingId, currentKey), this.applyValueTransaformation(mapERParametersEnumerator.currentValue()));
            }
        }

        return retVal;
    }

    /// <summary>
    /// Gets name of the GER format paramter name from key.
    /// </summary>
    /// <param name = "_formatMappingId">Id of the GER format.</param>
    /// <param name = "_key">Name of the GER format parameter.</param>
    /// <returns>Name of the GER format paramter.</returns>
    protected str getERParameterFromKey(ERFormatMappingId _formatMappingId, str _key)
    {
        return subStr(_key, strLen(int642Str(_formatMappingId)) + 1, strLen(_key));
    }

    public anytype applyValueTransaformation(anytype _localDateTime)
    {
        var retVal = _localDateTime;

        if (SL.TypeHelper::IsUtcDateTimeType(retVal.GetType()))
        {
            if (retVal.GetType() is SL.utcdatetime)
            {
                retVal = ERDateTimeUtils::convertFromUserTimeZoneToUTC(retVal);
            }
            else
            {
                retVal = ERDateTimeUtils::convertFromUserTimeZoneToUTC(ERLFConvert::fromUtcdatetime(retVal));
            }
        }

        return retVal;
    }

    /// <summary>
    /// indicates if info log should be shown
    /// </summary>
    /// <returns>boolean</returns>
    public boolean showInfolog()
    {
        return false;
    }

    /// <summary>
    /// indicates if report should be run in draft mode
    /// </summary>
    /// <returns>boolean</returns>
    public boolean forceRunDraft()
    {
        return false;
    }

    /// <summary>
    /// indicates if dialog prompt should be shown
    /// </summary>
    /// <param name = "_showDestination">NoYes</param>
    /// <returns>boolean</returns>
    public boolean showPromptDialog(NoYes _showDestination)
    {
        return _showDestination == NoYes::Yes;
    }

    /// <summary>
    /// indicates if query values should be shown
    /// </summary>
    /// <returns>boolean</returns>
    public boolean showQueryValues()
    {
        return false;
    }

}
 
 
Controller class:
 
/// <summary>
/// Controller class for ER price list report
/// </summary>
public class AVAInventTransferPackingSlipReportControllerCls extends SysOperationServiceController //extends ERFormatMappingRunBaseController
{
    List extraParamObjectList;

    public static void main(Args _args)
    {
        AVAInventTransferPackingSlipReportControllerCls::construct().runReportController(_args);
    }

    public static AVAInventTransferPackingSlipReportControllerCls construct()
    {
        return new AVAInventTransferPackingSlipReportControllerCls(classStr(AVAInventTransferPackingSlipReportServiceCls),
            methodStr(AVAInventTransferPackingSlipReportServiceCls, runReport),
            SysOperationExecutionMode::Synchronous);
    }

    /// <summary>
    /// method to init controller and start operation
    /// </summary>
    /// <param name = "_args">Args</param>
    public void runReportController(Args _args)
    {
        this.parmDialogCaption(this.caption());

        if (this.initAndValidateParameters(_args))
        {
            this.startOperation();
        }
        else
        {
            throw Exception::Error;
        }
    }

    /// <summary>
    /// init and validate contract parameters
    /// </summary>
    /// <param name = "_args">Args</param>
    /// <returns>boolean</returns>
    public boolean initAndValidateParameters(Args _args)
    {
        this.initDataContract(this.getDataContractObject(), _args);

        return this.validateDataContractInitParameters();
    }

    /// <summary>
    /// init data contract parameters
    /// </summary>
    /// <param name = "_contract">AVAInventTransferPackingSlipReportContractCls</param>
    /// <param name = "_args">Args</param>
    public void initDataContract(AVAInventTransferPackingSlipReportContractCls _contract, Args _args)
    {
        _contract.initFromArgs(_args);
        _contract.parmShowDestination(this.showDestination());
        _contract.parmFormatMapping(this.getSetupFormatMappingId());
        _contract.parmFileName(this.getFileNameWithoutExtension());
    }

    /// <summary>
    /// validates that the contract has parameters
    /// </summary>
    /// <returns>boolean</returns>
    public boolean validateDataContractInitParameters()
    {
        boolean                                         ret             = true;
        AVAInventTransferPackingSlipReportContractCls   dataContract    = this.getDataContractObject();

        if (!dataContract.parmFormatMapping())
        {
            throw Error(strFmt("@AVAExtension:ER_InventTransferPackingSlipError", "@SYS25197", "@SYS333869", "@SYS336190", "@SYS78286"));
        }

        return ret;
    }

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

    public ClassDescription caption()
    {         
        return "@AVAExtension:ER_InventTransfer_PackingSlip";
    }

    public ERModelMappingID getSetupFormatMappingId()
    {
        return WHSParameters::find().AVAERInventTransferPackingSlipFormatMapping;
    }

    /// <summary>
    /// IdentifierName of data contract
    /// </summary>
    /// <returns>IdentifierName</returns>
    public IdentifierName contractServiceParamName()
    {
        return identifierStr(_dataContract);
    }

    public Filename getFileNameWithoutExtension()
    {
        return "@AVAExtension:ER_InventTransfer_PackingSlip";
    }

    /// <summary>
    /// indicates if destinations should be shown
    /// </summary>
    /// <returns>NoYes</returns>
    public NoYes showDestination()
    {
        return NoYes::Yes;
    }

    public boolean showQuerySelectButton(str parameterName)
    {
        return false;
    }

}
 
 
Categories:
I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 764 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 619 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 603 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans