Sunday, April 11, 2021

Add new fields in sysoperation dialog and get the values in controller class in AX

UIBuilder class

[ExtensionOf(classstr(ExchangeRateImportUIBuilder))]
final class PDPExchangeRateImportUIBuilder_Extension
{
    public FormBuildIntControl      intCtrl;
    public FormBuildCheckBoxControl booleanCtrl;

    public void build()
    {
        next build();

        DialogField                 dialogField;
        DialogField                 dialogFieldNoYesId;
        ExchangeRateImportRequest   dataContract1;
        FormBuildCheckBoxControl    exchangeRateFromPreviousDayControl;

        dataContract1    = this.dataContractObject();

       //  creating this field if standared code skips it to avoid type cast error in contoller at runtime
        if(exchangeRateFromPreviousDayControl == null)
        {
            dialogField = dialog.addField(extendedtypestr(ExchangeRateFromPreviousDay));
            exchangeRateFromPreviousDayControl = dialogField.control();
            exchangeRateFromPreviousDayControl.value(dataContract1.parmExchangeRateFromPreviousDay());
            exchangeRateFromPreviousDayControl.allowEdit(false);
            exchangeRateFromPreviousDayControl.visible(false);
        }

        dialogField     = dialog.addField(extendedtypestr(NumberOf),"integer","integer");
        intCtrl         = dialogField.control();
        intCtrl.value(dataContract1.parmInteg());

        dialogField     = dialog.addField(extendedtypestr(NoYesId),"boolean","boolean");
        booleanCtrl     = dialogField.control();
        booleanCtrl.value(dataContract1.parmNoYesId());
    }

}

Contract class

[ExtensionOf(ClassStr(ExchangeRateImportRequest))]
[DataContractAttribute]
final class PDPExchangeRateImportRequest_Extension
{
    public int     integ;
    public NoYesId noYesValue;

    /// <summary>
    /// data memeber attribute of Integ field
    /// </summary>
    /// <param name = "_integ">integ</param>
    /// <returns>int</returns>
    [DataMemberAttribute]
    public int parmInteg(int _integ = 0)
    {
        if (!_integ)
        {
            integ = _integ;
        }

        return integ;
    }

    /// <summary>
    /// NoyesId field
    /// </summary>
    /// <param name = "_noYesValue">NoYesValue</param>
    /// <returns>boolean</returns>
    [DataMemberAttribute]
    public NoYesId parmNoYesId(NoYesId _noYesValue = NoYes::No)
    {
        if (!_noYesValue)
        {
            noYesValue = _noYesValue;
        }

        return _noYesValue;
    }

}

Controller class

[ExtensionOf(ClassStr(ExchangeRateImportController))]
final class PDPExchangeRateImportController_Extension
{
    public const str numberof = 'Fld11_1';
    public const str noYesValue = 'Fld12_1';


    public void getFromDialog()
    {
        next getFromDialog();

        FormRun                             theDialogForm;
        ExchangeRateImportRequest           exchangeRateImportRequest;
        ExchangeRateProviderFactory         factory;

        FormIntControl intCtrl;
        FormCheckBoxControl booleanCtrl;
        FormCheckBoxControl exchangeRateFromPreviousDayControl;
       
        exchangeRateImportRequest = this.getDataContractObject(classStr(ExchangeRateImportRequest));
        theDialogForm = this.dialog().formRun();

        intCtrl = theDialogForm.control(theDialogForm.controlId(numberof));

        booleanCtrl = theDialogForm.control(theDialogForm.controlId(noYesValue));

        exchangeRateImportRequest.parmInteg(intCtrl.value());

        exchangeRateImportRequest.parmExchangeRateTypeRecId(booleanCtrl.value());

        Info(strFmt("%1--%2",intCtrl.value(), booleanCtrl.value()));

    }

}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8