0
votes

I was wondering if anyone knew of a way to prevent certain fields from updating with default/stored data when updating the Customer field on the Sales Order page under a certain condition.

My Goal: When on the Sales Order page, if a certain Order Type is selected (in this case, the order type that signifies it is a Sales Order created and sent from our website), changing the Customer Field does not update/overwrite the Financial Settings or the Shipping Settings. This is because the Financial and Shipping settings fields are populated and sent from the website, and may have more specific information than the stored Customer information.

I want to keep the loading of default data for other tabs/fields, but keep the customer-entered billing and shipping info.

enter image description here

1

1 Answers

2
votes

The SOOrder_CustomerID_FieldUpdated event on the sales order graph updates all related customer information based on the change of customer id. You can override it in a graph extension. The contact and address information is used as an ID to another table so all you need to do is keep the same contact or address ID. I tested the following graph extension and it seems to work by keeping the ID values before calling the base method.

public class SOOrderEntryMyExtension : PXGraphExtension<SOOrderEntry>
{
    protected virtual void SOOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated del)
    {
        var order = (SOOrder)e.Row;
        var oldCustomerID = (int?)e.OldValue;
        var orderBeforeBase = (SOOrder)cache.CreateCopy(order);

        del?.Invoke(cache, e);

        if (order == null || orderBeforeBase == null || oldCustomerID == null || order.CustomerID == oldCustomerID || order.OrderType != "WO")
        {
            return;
        }

        if (order.BillAddressID != orderBeforeBase.BillAddressID)
        {
            cache.SetValueExt<SOOrder.billAddressID>(order, orderBeforeBase.BillAddressID);
        }

        if (order.BillContactID != orderBeforeBase.BillContactID)
        {
            cache.SetValueExt<SOOrder.billContactID>(order, orderBeforeBase.BillContactID);
        }

        if (order.ShipAddressID != orderBeforeBase.ShipAddressID)
        {
            cache.SetValueExt<SOOrder.shipAddressID>(order, orderBeforeBase.ShipAddressID);
        }

        if (order.ShipContactID != orderBeforeBase.ShipContactID)
        {
            cache.SetValueExt<SOOrder.shipContactID>(order, orderBeforeBase.ShipContactID);
        }
    }
}