Warm tip: This article is reproduced from stackoverflow.com, please click
axapta dynamics-365-operations microsoft-dynamics x++

Is it possible to create 1 event handler for 2 formDataSourceStr? X++

发布于 2020-05-09 18:00:33

Change of question. How to override correctly modified field in purchcreateorder? Right now it compiles but still the values didnt show in my form.

[ExtensionOf(formdatasourcestr(PurchCreateOrder, PurchTable))]
final class PurchCreateOrderGetDefAdress_Extension
{

[DataField]
class OrderAccount
{
    void modified()
    {

        element.orderAccountModified();
        InventLocation                              inventlocation;
        UserInfoSz                                  usrsz;
        PurchTable purchtable;
        FormDataSource ds;
        FormDataObject df =any2Object(this) as FormDataObject;

        next Modified();

        ds = df.datasource();
        PurchTable = Ds.cursor();

        select InventLocation where InventLocation.inventsiteid == usrsz.InventSiteId && inventlocation.DefaultShipMaintenanceLoc == 'out';

        purchtabke.orderaccount = '11111111111111111111';
        purchtable.inventsiteid = 'ILA-LOG-01';// InventLocation.inventsiteid;
        purchtable.inventlocationid = InventLocation.InventLocationId;
        purchtable.DeliveryName = 'sasasasa';
        //purchTable_ds.refresh();

    }
    }
Questioner
Radosław Mierzejewski
Viewed
22
Aliaksandr Maksimau 2020-02-25 22:33

To avoid code duplication in your case, create a static method in your event handler class and put your code there

public static void initLogisticsPostalAddress(...parameters...)
{
    put your logic here   
}

then call this method in both events:

[FormDataSourceEventHandler(formDataSourceStr(PurchCreateOrder, PurchTable), FormDataSourceEventType::initvalue)]
public static void PurchTable_Oninitvalue(FormDataSource sender, FormDataSourceEventArgs e)
{
    PurchCreateOrderEH::initLogisticsPostalAddress(...parameters...);
}