0

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();

    }
    }
Aliaksandr Maksimau
  • 2,251
  • 12
  • 21
Tweene
  • 257
  • 4
  • 16
  • It is not clear why CoC is not an option and what error do you have, but the general way to avoid code duplication is to put it into a separate method and call it when necessary. – Aliaksandr Maksimau Feb 25 '20 at 08:32
  • So as I see I need to keep 2 events. Could you kindly show me how to call items from this method or how should I do it? Do I need to keep declarations in events ? calling results from select ? Well I have abnormal termination error with just the CoC in my class. – Tweene Feb 25 '20 at 08:43

1 Answers1

2

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...);
}
Aliaksandr Maksimau
  • 2,251
  • 12
  • 21
  • Great. One more question. Since I try to init values I want to keep them even after I change PurchTable_orderaccount in PurchCreateOrder. Right now when I select a order account my init values are replaced. How can I prevent it ? – Tweene Feb 25 '20 at 13:19
  • Why don't you put your init logic in a `modified`method of `OrderAccount` datasource field instead of `Oninitvalue` events? – Aliaksandr Maksimau Feb 25 '20 at 14:31
  • Tried it now but my values didnt show up. Edited code in my post – Tweene Feb 26 '20 at 07:47
  • Okay I got it. Forgot I can use events on fields. So I created a onmodified eventhandler any my values are updating right. Last but stil. Could you say me how can I select deliveryname, inventsiteid and inventlocationid from purchtable ? Every time I try I get nothing. while select firstonly InventSiteId, InventLocationId, DeliveryPostalAddress, DeliveryName from purch group by purch.DeliveryPostalAddress, purch.deliveryname where purch.InventSiteId == usrsz.InventSiteId && purch.InventLocationId != null && purch.InventSiteId != null – Tweene Feb 26 '20 at 08:01