21 April 2021

Enable / Disable the dialog field using UIBuilder in Service class / SysOperation fremework

 class TRGIntCalcBorrowingCostUIBuilder extends SysOperationAutomaticUIBuilder

{

    private TRGIntCalcBorrowingCostContract intCalcBorrowCostContract;

    private DialogField dialogPeriodCode;



    /// <summary>

    /// Auguments the UI behavior.

    /// </summary>

    public void postBuild()

    {

        intCalcBorrowCostContract = this.dataContractObject();

        super();

        dialogPeriodCode = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TRGIntCalcBorrowingCostContract, parmPeriod));

        dialogPeriodCode.enabled(false);

    }


}

09 April 2021

Looping selected records in the form in D365FO and X++ code to loop form selected records.


When the class main method initiated there can pass the args.record to below method and can loop records.

Reference: Class: PurchReqCancel

private void runLoopCancelWin(Common _common)
    {
        FormDataSource fds            = FormDataUtil::getFormDataSource(_common);
        Common         common;

        for (common = fds.getFirst(1) ? fds.getFirst(1) : fds.cursor(); common; common = fds.getNext())
        {
            this.doCancel(common);
        }
    }








02 March 2021

Dynamics 365 FO Extension for Form Datasource field and to get the current record

 [ExtensionOf(formdatafieldstr(EntAssetRequestTableCreate, RequestTable, Object))]

final class TRGEntAssetRequestTableCreateFDF_RT_Object_Extension

{  

    public void modified()

    {

        FormDataObject dataObject = any2Object(this) as FormDataObject;

        next modified();        

        FormDataSource fds = dataObject.dataSource().formRun().dataSource(formDataSourceStr(EntAssetRequestTableCreate, TRGEntAssetRequestObjectTableView));

        fds.executeQuery();

    }

Dynamics AX 365 FO – How to register jumpref method on form control / get the jumpref link in the form control

Create an event for OnPostRun for form events

[FormEventHandler(formStr(EntAssetWorkOrderTableCreate), FormEventType::PostRun)]

    public static void EntAssetWorkOrderTableCreate_OnPostRun(xFormRun sender, FormEventArgs e)

    {

        FormStringControl formCtrl = sender.design().controlName(formControlStr(EntAssetWorkOrderTableCreate, TRGEntAssetRequestObjectTableView_RequestId));

        formCtrl.registerOverrideMethod(methodStr(FormStringControl, jumpRef), methodStr(EntAssetRequestTableCreateForm_Extension, jumpRefRequestId), sender);

    }

Create extension class for the form methods and add jumprefMethod in it:

[ ExtensionOf(formstr(EntAssetWorkOrderTableCreate)) ]

final class TRGEntAssetWorkOrderTableCreateForm_Extension

{    

    public void TRGJumpRefRequestId(FormControl _formControl)

    {

        MenuFunction                        menuFunction;

        EntAssetRequestTable                entAssetRequestTable;

        TRGEntAssetRequestObjectTableView   entAssetRequestObjectTableView;

        Args                                args = new Args();

        FormDataSource                      fds = _formControl.formRun().dataSource(formDataSourceStr(EntAssetWorkOrderTableCreate, TRGEntAssetRequestObjectTableView));

        entAssetRequestObjectTableView      = fds.cursor();

        if (_formControl)

        {

            entAssetRequestTable = EntAssetRequestTable::find(entAssetRequestObjectTableView.RequestId);

        }

        args.record(entAssetRequestTable);

        args.lookupRecord(entAssetRequestTable);

        menuFunction = new MenuFunction(menuitemDisplayStr(EntAssetRequestTable), MenuItemType::Display);

        menuFunction.run(args);

    }

}

01 March 2021

How to fix BP warning in Dynamics 365 FO

 Need to add the SuppressBPWarning for methods if not using any Parameters:

Example:

[FormDataSourceEventHandler(formDataSourceStr(EntAssetRequestTableCreate, TRGEntAssetRequestObjectTableView), FormDataSourceEventType::QueryExecuting),

        SuppressBPWarning('BPParameterNotUsed', 'The parameter is not required in this context')]

    public static void TRGEntAssetRequestObjectTableView_OnQueryExecuted(FormDataSource sender, FormDataSourceEventArgs e)

    {


=====

[FormDataSourceEventHandler(formDataSourceStr(AccountingDistribution, AccountingDistribution), FormDataSourceEventType::Activated),

        SuppressBPWarning('BPParameterNotUsed', 'Parameter required by the event interface')]

27 February 2021

Capturing infolog error messages in AX 2012 X++ code to capture the error infolog

InfologData             infoLogData;

SysInfologEnumerator    sysInfologEnumerator;

 sysInfologEnumerator = SysInfologEnumerator::newData(infolog.infologData());

 while (sysInfologEnumerator.moveNext() )

 {

        switch (sysInfologEnumerator.currentException())

        {         

            case Exception::Warning:

                 info(strFmt("Message is %1", sysInfologEnumerator.currentMessage()));

            break;

        }

}

=============

 catch (Exception::CLRError)

                {

                    ex = ClrInterop::getLastException();

                    if (ex != null)

                    {

                        ex = ex.get_InnerException();

                        if (ex != null)

                        {

                            error(ex.ToString());

                        }

                    }

                }

25 February 2021

D365FO COC methods and usage

How to get Form data source field method COC current record:

FormDataObject dataObject = any2Object(this) as FormDataObject;

FormDataSource dataSource = dataObject.DataSource();

CustGroup custGroup = dataSource.cursor();


How to add the Display method in the form level in D365 F&O

 The below examle is to add the form -Data source level adding display method and assigning to form design control.