Dynamics 365 FO - Form extensions - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Saturday, September 17, 2022

Dynamics 365 FO - Form extensions

 Dynamics 365 FO - Form extensions

Nghia Song -  Microsoft Dynamics 365 Technical Consultant

Nghia Song

Tel - WhatsApp: +84967324794

Email: songnghia.uit@gmail.com


Form extensions

You can extend the functionality of a form by extending its controls and data sources. For example, in a form extension, you can:

  • Add a new control.

  • Enable or disable a control.

  • Change the text or label property of a control.

  • Change a control's visibility.

  • Change a form's help text.

  • Change a form's caption.

  • Add a new data source.

  • Add a form part.

Other ways to customize a form, such as reordering controls in the form are planned to be included in a future release. In Microsoft Dynamics AX 2012, you could override form methods. In the current version, you use extensions to implement event handlers that are called from the base implementations of form methods. The following table lists each method and its associated events.


Published form DataSource method

Preceding event

Succeeding event

active

N/A

Activated

delete

Deleting

Deleted

validateWrite

ValidatingWriting

ValidatedWrite

write

Writing

Written

create

Creating

Created

executeQuery

N/A

QueryExecuted

linkActive

N/A

PostLinkActive

init

N/A

Initialized

validateDelete

ValidatingDelete

ValidatedDelete

reread

N/A

Reread

selectionChanged

N/A

SelectionChanged

markChanged

N/A

MarkChanged

leaveRecord

LeavingRecord

LeftRecord

Published form Object method

Preceding event

Succeeding event

init

Initializing

Initialized

close

Closing

N/A

run

N/A

PostRun

activate

N/A

Activated

Published form Control method

Preceding event

Succeeding event

modified

N/A

Modified

validate

Validating

Validated

leave

Leaving

LostFocus

enter

N/A

Enter

gotFocus

N/A

GotFocus

clicked

N/A

Clicked

selectionChange

SelectionChanging

N/A

pageActivated

N/A

PageActivated

allowPageDeactivate

AllowPageDeactivate

N/A

expand

Expanding

Expanded

tabChanged

N/A

TabChanged

dialogClosed

N/A

DialogClosed


Form event handler sample

FormControlEventType::Clicked

    [FormControlEventHandler(formControlStr(CustOpenTrans, MarkOrderTotal), FormControlEventType::Clicked),


    public static void MarkOrderTotal_OnClicked(FormControl sender, FormControlEventArgs e)

    {

        FormRun formRun = sender.formRun() as FormRun;

        FormRun formRunParent = formRun.args().caller();

        Common originator = formRun.args().record();

        FormDataSource custTransOpen_ds = formRun.dataSource('CustTransOpen');

        CustTransOpen custTransOpen = custTransOpen_ds.cursor();


    }


    FormControlEventType::Lookup

        [FormControlEventHandler(formControlStr(SalesTable, SalesLine_TruckShipmentId), FormControlEventType::Lookup),

        SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]

    public static void SalesLine_TruckShipmentId_OnLookup(FormControl sender, FormControlEventArgs e)

    {

        SalesLine salesLine = sender.dataSourceObject().cursor();

    }


    FormDataSourceEventType::Activated

    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated),

        SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]

    public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

    {

        SalesLine salesLine;



        salesLine = sender.cursor();


    }


    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated)]

    public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

    {

        FormRun formRun = sender.formRun();

        SalesTable saleTable;


        FormDataSource salesTableDS = formRun.dataSource(formDataSourceStr(SalesTable, SalesTable)) as FormDataSource;

        saleTable = salesTableDS.cursor();

    }

    FormDataFieldEventType::Modified

     [FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, DlvMode), FormDataFieldEventType::Modified)]

    public static void DlvMode_OnModified(FormDataObject sender, FormDataFieldEventArgs e)

    {

        SalesLine salesLine;


        salesLine = sender.datasource().cursor();

    }


    Form field mandatory

     [FormDataFieldEventHandler(formDataFieldStr(SalesTable, FreightThirdPartyBilling, FreightBillAccount), FormDataFieldEventType::Modified)]

    public static void FreightBillAccount_OnModified(FormDataObject sender, FormDataFieldEventArgs e)

    {

        FormDataSource thirdPartyBillingDS;

        FreightThirdPartyBilling thirdPartyBilling;

        boolean allowEdit;

        FormStringControl cityCtrl;


        thirdPartyBillingDS = sender.datasource();

        thirdPartyBilling = sender.datasource().cursor();


        cityCtrl = thirdPartyBillingDS.formRun().design().controlName(formControlStr(SalesTable, FreightThirdPartyBilling_City));

        cityCtrl.mandatory(allowEdit);


    }



    Form field modified and inserting into fields based on record.



     [FormDataFieldEventHandler(formDataFieldStr(PurchTable, PurchTable, VendFactoryAddress), FormDataFieldEventType::Modified)]

    public static void VendFactoryAddress_OnModified(FormDataObject sender, FormDataFieldEventArgs e)

    {

        LogisticsPostalAddress logisticsPostalAddress;

        int64 factoryAdress;


        factoryAdress = sender.getValue();


        select firstonly logisticsPostalAddress where logisticsPostalAddress.RecId == factoryAdress;

        sender.datasource().object(fieldNum(PurchTable, CountryRegId)).setValue(logisticsPostalAddress.CountryRegionId);

        sender.datasource().object(fieldNum(PurchTable, TransactionCode)).setValue(logisticsPostalAddress.TransactionCode);

        sender.datasource().object(fieldNum(PurchTable, Port)).setValue(logisticsPostalAddress.PortId);

        sender.datasource().object(fieldNum(PurchTable, IntermediaryCode)).setValue(logisticsPostalAddress.IntermediaryCode);



    }


    Form method Post event Handler

    [PostHandlerFor(formStr(SalesTable), formMethodStr(SalesTable, enableTMSFields))]

    public static void SalesTable_Post_enableTMSFields(XppPrePostArgs args)

    {

        FormRun salesTableForm = args.getThis();

        Common common = salesTableForm.args().record();

        SalesTable salesTab;

        FormStringControl carrierCode = salesTableForm.design(0).controlName(formControlStr(SalesTable, TMSSalesTable_CarrierCode));


        FormDataSource tmsSalesTableDatasource = salesTableForm.dataSource(formDataSourceStr(SalesTable, TMSSalesTable)) as FormDataSource;

        salesTab = salesTableDS.cursor();

    }


    FormDataSourceEventType::SelectionChanged

    [FormDataSourceEventHandler(formDataSourceStr(LogisticsPostalAddressGrid, DirPartyPostalAddressView), FormDataSourceEventType::SelectionChanged)]

    public static void DirPartyPostalAddressView_OnSelectionChanged(FormDataSource sender, FormDataSourceEventArgs e)

    {

        var formRun = sender.formRun() as FormRun;

        str callerFormName = formRun.args().caller().Name();


        if (callerFormName == formStr(Decorator))

        {

            var dirPartyPostalAddDatasource = formRun.dataSource(formDataSourceStr(LogisticsPostalAddressGrid, DirPartyPostalAddressView)) as FormDataSource;

            if (dirPartyPostalAddDatasource.numberOfRowsLoaded() > 0)

            {

                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, NewAddress))).enabled(false);

                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, MoreOptions))).enabled(false);

            }

            else

            {

                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, NewAddress))).enabled(true);

                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, MoreOptions))).enabled(true);

            }

        }

    }

Next:Dynamics 365 FO - View, Data entity, Enum, EDT, Query, Menu, Seciruty, Role, Duty, Report, Label, extensions

No comments:

Post a Comment