从BAccountMaint扩展更新客户(错误#91另一个进程已更新..)

时间:2017-04-20 22:18:37

标签: acumatica

我已使用新的UsrAccountType字段扩展了业务帐户DAC。通过业务帐户维护图更新该字段时,我还需要更新相关客户记录中的各个字段。但是,当持续存在"错误#91:另一个进程已更新' BAccount'记录。您的更改将会丢失。"发生。

首先,我只是尝试将Customer.customerClassID字段设置为与Account Type相同的值,Account Type是Customer Classes&的一个子集。与更改客户类相关的其他字段的更改无需应用。

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

如何在BAccount的同时更新客户?我是否需要创建一个CustomerMaint图并通过它更新记录 - 这是否会导致两个记录同时更新时出现同样的问题?或者可以在持有BAccount更改并在那里完成对客户的更改后,在BAccount_RowPersisted中完成某些操作?

1 个答案:

答案 0 :(得分:1)

此行为的根本原因是客户来自BAccount。

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

因此,如果您更新客户记录,BAccount记录也将更新。

要绕过这一点,您必须创建自己的客户DAC,而不是从BAccount派生并更新它。

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