Search code examples
acumatica

How to attach an event to the Residential Delivery checkbox on the Customers screen in 2020R2?


I need to change the default value of the Residential Delivery checkbox on the Customers AR.30.30.00 screen (Shipping tab) to checked by default. See screenshot:

enter image description here

In 2017R2, this event handler worked without error:

public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{
    protected virtual void LocationExtAddress_CResedential_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        var row = (LocationExtAddress)e.Row;
        if (row != null)
        {
            e.NewValue = true; // checked by default
        }
    }
}

I'm updating this customization for 2020R2. It appears that LocationExtAddress has been replaced with DefLocationExt in newer versions. (Resedential is mis-spelled intentionally in the code... that's how Acumatica defined it.) I've tried changing the event handler to:

protected virtual void DefLocationExt_CResedential_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
    var row = (DefLocationExt)e.Row;
    if (row != null)
    {
        e.NewValue = true; // checked by default
    }
}

But this results in a run-time error:

Failed to subscribe the event PX.Objects.AR.CustomerMaint_Extension::DefLocationExt_CResedential_FieldDefaulting in the graph PX.Objects.AR.CustomerMaint. The method signature looks like an event handler, but the cache DefLocationExt has not been found in the list of auto-initialized caches. Remove unused event handlers from the code.

How can I attach an event to this field in 2020R2?


Solution

  • Try a generic event handler and see if you get the same result.

    It might look something like this.

    protected virtual void _(Events.FieldDefaulting<PX.Objects.CR.Standalone.Location.cResedential> e)
        {
            var row = (PX.Objects.CR.Standalone.Location)e.Row;
            if (row != null)
            {
                e.NewValue = true; // checked by default
            }
        }