0
votes

I have extended the Business Accounts DAC with a new UsrAccountType field. When that field is updated through the Business Accounts maintenance graph I also need to update various fields in the related Customer record. However, when persisting an "Error #91: Another process has updated 'BAccount' record. Your changes will be lost." occurs.

To start I'm just trying to set the Customer.customerClassID field to the same value as the Account Type which is a sub-set of Customer Classes & changes to other fields related to changing the customer class need not apply.

public class BusinessAccountMaint_Extension : PXGraphExtension<BusinessAccountMaint>
{
    public PXSelect<Customer, Where<Customer.bAccountID, Equal<Current<BAccount.bAccountID>>>> ARCustomer;

    public virtual void BAccount_UsrAccountType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
    {
        BAccount row = (BAccount)e.Row;
        if (row == null) return;
        BAccount_Extension rowExt = row.GetExtension<BAccount_Extension>();

        Customer customer = ARCustomer.Current;
        if (customer == null) return;

        customer.CustomerClassID = rowExt.UsrAccountType;
        // additional changes to Customer record
        this.Base.Caches<Customer>().Update(customer);
    }
}

How can I update the Customer at the same time as the BAccount? Do I need to create a CustomerMaint graph and update the record through it -- would that not cause the same issue with both record being updated at the same time? Or can something be done in the BAccount_RowPersisted after the BAccount changes have been persisted and the changes to the Customer be done there?

1

1 Answers

1
votes

The root cause of this behavior is that customer is derived from BAccount.

[PXCacheName(Messages.Customer)]
[PXEMailSource]
public partial class Customer : BAccount, PX.SM.IIncludable
{

So, if you update Customer record, BAccount record will be updated too.

To bypass that, you have to create your own customer DAC not derived from BAccount and update it.

namespace  SomeNamespce
{
     [Serializable]
    public partial class Customer : IBqlTable
    {
        public abstract class bAccountID : PX.Data.IBqlField
        {
        }
        [PXDBIdentity((IsKey = true))]
        public virtual int? BAccountID
        {
            get;
            set;
        }
        public abstract class customerClassID : PX.Data.IBqlField
        {
        }
        [PXDBString(10, IsUnicode = true)]
        //[PXDefault(typeof(Search<ARSetup.dfltCustomerClassID>))]
        //[PXSelector(typeof(CustomerClass.customerClassID), DescriptionField = typeof(CustomerClass.descr), CacheGlobal = true)]
        public virtual String CustomerClassID
        {
            get;
            set;
        }
    }
}
namespace  YourNamespace
{ 
    public class BusinessAccountMaint_Extension : PXGraphExtension<BusinessAccountMaint>
    {
        public PXSelect<SomeNamespce.Customer , Where<SomeNamespce.Customer.bAccountID, Equal<Current<BAccount.bAccountID>>>> ARCustomer;

        public virtual void BAccount_UsrAccountType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            BAccount row = (BAccount)e.Row;
            if (row == null) return;
            BAccount_Extension rowExt = row.GetExtension<BAccount_Extension>();

            SomeNamespce.Customer customer = ARCustomer.Current;
            if (customer == null) return;

            customer.CustomerClassID = rowExt.UsrAccountType;
            // additional changes to Customer record
            ARCustomer.Update(customer);
        }
    }
}