删除客户时,如何为Acumatica中分配的联系人的自定义字段设置空值

删除客户时,如何为Acumatica中分配的联系人的自定义字段设置空值,acumatica,acumatica-kb,Acumatica,Acumatica Kb,我尝试了多种方法,但在Acumatica 19.106.0020的默认版本中出现了另一个过程错误 除此之外,我在客户和联系人屏幕上都有一个自定义代码,当客户从屏幕AR303000中删除时,我需要清除在联系人表中创建的自定义字段的值,我需要为客户删除的联系人设置自定义字段的空值 我尝试过在Customer_Row事件上设置值,但不断地得到另一个流程错误,下面是屏幕截图错误 下面是我尝试过的代码 protected virtual void Customer_RowDeleting(PXCach

我尝试了多种方法,但在Acumatica 19.106.0020的默认版本中出现了另一个过程错误

除此之外,我在客户和联系人屏幕上都有一个自定义代码,当客户从屏幕AR303000中删除时,我需要清除在联系人表中创建的自定义字段的值,我需要为客户删除的联系人设置自定义字段的空值

我尝试过在Customer_Row事件上设置值,但不断地得到另一个流程错误,下面是屏幕截图错误

下面是我尝试过的代码

 protected virtual void Customer_RowDeleting(PXCache sender, PXRowDeletingEventArgs e, PXRowDeleting BaseEvent)
        {
            BaseEvent?.Invoke(sender, e);
            Customer rows = e.Row as Customer;
            if (rows == null)
                return;
            if (Base.BAccount.Cache.GetStatus(Base.BAccount.Current) == PXEntryStatus.Deleted)
            {
                foreach (Contact BACT in PXSelectReadonly<Contact,
                                   Where<Contact.bAccountID, Equal<Required<Contact.bAccountID>>,
                                   And<Contact.contactType, NotEqual<ContactTypesAttribute.bAccountProperty>>>>.Select(Base, rows.BAccountID))
                {
                    ContactMaint congraph = PXGraph.CreateInstance<ContactMaint>();
                    Contact CTData = PXSelectReadonly<Contact,
                        Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.Select(Base, BACT.ContactID);
                    if (CTData != null)
                    {
                        congraph.Contact.Current = CTData;
                        if (congraph.Contact.Current != null)
                        {
                            congraph.Contact.SetValueExt<ContactExt.usrKWBAccountId>(congraph.Contact.Current, null);
                            congraph.Contact.Update(congraph.Contact.Current);
                            congraph.Save.Press();
                        }
                    }
                }
            }
        }
protected virtual void Customer\u RowDeleting(PXCache发送方、PXRowDeletingEventArgs e、PXRowdeleding BaseEvent)
{
BaseEvent?调用(发送方,e);
客户行=即作为客户的行;
if(行==null)
返回;
if(Base.BAccount.Cache.GetStatus(Base.BAccount.Current)==PXEntryStatus.Deleted)
{
foreach(联系PXSelectReadonly.Select(Base,rows.BAccountID)中的BACT)
{
ContactMaint Congaph=PXGraph.CreateInstance();
联系人CTData=PXSelectReadonly.Select(基本、基本、联系人ID);
如果(CTData!=null)
{
Congaph.Contact.Current=CTData;
if(congaph.Contact.Current!=null)
{
Congaph.Contact.SetValueExt(Congaph.Contact.Current,null);
Congaph.Contact.Update(Congaph.Contact.Current);
congraph.Save.Press();
}
}
}
}
}
提前谢谢

嗨,克里斯,请在这里找到附件中的图片


我不建议在行删除事件期间创建图。如果安装了Acuminator,您将看到关于在事件处理程序中创建图形的警告。 相反,在Persist方法期间调用自定义代码。在删除操作期间调用Persist方法。基本持久化完成后,您的自定义代码可以执行它的工作。试试这样的

public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{        
    public delegate void PersistDelegate();
    [PXOverride]
    public void Persist(PersistDelegate baseMethod)
    {   
        Customer currentCustomer = Base.CurrentCustomer.Current;  //get the customer record before it's deleted, i.e. Customer.bAccountID
        baseMethod();  //let the base delete process happen first
        if (Base.CurrentCustomer.Cache.GetStatus(currentCustomer) == PXEntryStatus.Deleted)
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                //here is where you add your code to delete other records

                ts.Complete();    //be sure to complete the transaction scope
            }
        }
    }
}
公共类CustomerMain_扩展:pxGrapherExtension
{        
公共委托void PersistDelegate();
[PXOverride]
公共void Persist(PersistDelegate baseMethod)
{   
Customer currentCustomer=Base.currentCustomer.Current;//在删除之前获取客户记录,即Customer.bAccountID
baseMethod();//让基本删除过程先进行
if(Base.CurrentCustomer.Cache.GetStatus(CurrentCustomer)==PXEntryStatus.Deleted)
{
使用(PXTransactionScope ts=new PXTransactionScope())
{
//您可以在此处添加代码以删除其他记录
ts.Complete();//确保完成事务范围
}
}
}
}

另外,您可能希望取消发布其他自定义包,并查看在没有这些包的情况下错误是否继续。这是通过消除过程确定错误来源的一种方法。

嗨,Chris,这对我不起作用。在客户屏幕上执行删除操作时,我从currentcustomer视图中获取空值,你能参考上面随附的屏幕截图吗,也请建议我解决这个问题,我的自定义字段值未设置为null,但客户和各自的联系人正在删除,但自定义字段中的值未清除。